Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Adding header to request in HTTP Module

Reply
Thread Tools

Adding header to request in HTTP Module

 
 
nsyforce@aol.com
Guest
Posts: n/a
 
      07-25-2005
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.

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      07-25-2005
If the page isn't buffered, then this should work. On an unrelated note (or
maybe it is?), you don't need to call:

res.Output.Flush();

-Brock
DevelopMentor
http://staff.develop.com/ballen



> 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.
>




 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      07-26-2005
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

<> wrote in message
news: ups.com...
> 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.
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      07-26-2005
ieHttpHeaders v 1.6 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...
======================

"Kevin Spencer" <> wrote in message
news:...
> 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
>
> <> wrote in message
> news: ups.com...
>> 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.
>>

>
>



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      07-26-2005
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...
======================

<> wrote in message
news: ups.com...
> 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.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a HTTP header to a SOAPpy request Matias Surdi Python 3 06-21-2011 09:20 AM
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
Adding a header into a HTTP post request Giacecco Ruby 4 04-12-2006 03:34 PM
request object and http header tacoturtle ASP .Net 1 05-28-2004 07:05 AM
Redirecting HTTP traffic based on host-header (or URL request) Tim Mavers Cisco 3 04-13-2004 06:31 PM



Advertisments