Adding header to request in HTTP Module

  • Thread starter Thread starter nsyforce
  • Start date Start date
N

nsyforce

Can you add a header to a request in an http module? I'm trying
unsuccessfully. Here's an example of my code:

public void Init(HttpApplication r_objApplication)
{

r_objApplication.EndRequest += new
EventHandler(this.EndRequest)
}

protected void EndRequest(object sender, EventArgs e)
{
HttpResponse res = HttpContext.Current.Response;
res.AddHeader("MyTestHeaderVar","MyTestVarValue");
res.Output.Flush();
}

My test page then spits out all request.headers and all
request.servervariables and my header is not anywhere. Does anyone
know what I'm doing wrong?

Thanks in advance.
 
Headers are not visible in a browser. They are part of an HTTP message that
is not in the HTML of the message.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
The sun never sets on
the Kingdom of Heaven
 
Hi.

The ServerVariables collection returned by the Request object
only contains headers sent from the browser to the server.

Since your custom header was created on the server and then
sent to the browser (the opposite direction), your header will
never be added to the ServerVariables collection.

You should be aware of this if you ever plan to interrogate the
ServerVariables collection, expecting to find a custom header
you created in this way. It will never be there.

To check for custom headers added, use a tool like ieHttpHeaders v 1.6,
which shows the http headers in IE.

http://www.blunck.info/iehttpheaders.html

It's quite convenient to use when debugging...and it's free!




Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
Back
Top