Question

Some background information: I’ve created a custom handler and a custom module for IIS7 with the .NET Framework based on this blog-entry by Mike Volodarsky.

Everything is working fine so far with the handler & module but here’s my problem/scenario.

If a request on a given URL is recognized by the handler, I need to read a cookie, get its information and add those data to the headers of the incoming request.

Here’s my coding so far for the 'IHttpHandler' Member:

public void ProcessRequest(HttpContext context)
{
    var response = context.Response; 
    //var request = context.Request;
    var cookieInformation = GetSomeInformationFromCookie();
    if (!string.IsNullOrEmpty(cookieInformation))
    {
        var nameValueCollection = new NameValueCollection
                                         {{"CustomAspNetHeader", cookieInformation}};
        response.Headers.Add(nameValueCollection);
    }
    // I would like to proceed the current request 
    // just with the updated header-information.
}

Is there any possible way to update the header-information of an incoming request?

Let’s imaging we’ve a page called ‘MyPage.aspx’. In the PageLoad-Event we write something like:

foreach (var header in HttpContext.Current.Request.Headers)
{
    var value = HttpContext.Current.Request.Headers[header.ToString()];
    var s = string.Format("Header: <strong>{0}</strong>, Value: <strong>{1}</strong><br />", header, value);
    Response.Write(s);
}

Basically I get the following information out of the foreach-loop:

  • Header: Connection, Value: keep-alive
  • Header: Accept, Value: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
  • Header: Accept-Encoding, Value: gzip,deflate,sdch
  • Header: Accept-Language, Value: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
  • Header: Cookie, Value: ASP.NET_SessionId=242xbd55fxhxv055hfunnj55
  • Header: Host, Value: localhost:61045
  • Header: User-Agent, Value: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)

Now, we enable the handler to listen for files with the .aspx extension in IIS7-Manager. If we run the ‘MyPage.aspx’ for the second time, the PageLoad-Event is fired and shows all the header-information... And here’s my problem. I can’t see anything, because the handler is taking care of the incoming request of ‘MyPage.aspx’ and the PageLoad-Event is never reached/fired.

Maybe there’s another technique to update the header-information of an incoming request (in .NET).

Any help is greatly appreciated.

Était-ce utile?

La solution

Take the code from the Http handler that you have written and run it in global.asax.

Something like this:

protected void Application_BeginRequest()
{
    // Manipulate the headers as you see fit.
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top