mercredi 15 février 2017

How can I prepare an argument of type HttpContext for a method?

I am trying test a method. The method takes in a single argument, which belongs to the class HttpContext in NET Framework Class Library. So I guess I need to prepare an object of HttpContext.

All that the method needs from the argument, say context, are

  • context.Request.QueryString
  • context.Request.Headers

Here are my thoughts and questions

  1. To learn how to use HttpContext, I click going to definition in Visual Studio, I found that the class has a constructor

        public HttpContext(HttpRequest request, HttpResponse response);
    
    

    so I need to provide its two arguments, in order to create a object of the class.

    To provide an object of HttpRequest, I found its constructor

    //
    // Summary:
    //     Initializes an System.Web.HttpRequest object.
    //
    // Parameters:
    //   filename:
    //     The name of the file associated with the request.
    //
    //   url:
    //     The information regarding the URL of the current request.
    //
    //   queryString:
    //     The entire query string sent with the request (everything after the'?').
    public HttpRequest(string filename, string url, string queryString);
    
    
    • What does filename mean?

    • Which is url, the full url containing the query strings, or just the part before ??

  2. After I can create an object of HttpContext, do I need to call some method to parse the url and query strings to obtain

    • context.Request.QueryString
    • context.Request.Headers

    or the HttpContext will implicitly do the work without me explicitly calling any method?

Thanks.




Aucun commentaire:

Enregistrer un commentaire