Viewing Custom Headers

  • Comments 1
  • Likes

This tip comes from the 11/23/2004 edition of the IISAnswers Newsletter.  You can subscribe to the newsletter or find more information at  (Even better, if you're viewing this from the page, scroll to the bottom of the screen and subscribe right away)



I have an IIS 6 Server Cluster.  I'm trying to make a generic test page that will show me the cluster member I'm on.  I figured a good way to do this is to assign a Custom Header Variable to IIS such as "Node:" with a value of "1" or "2" or "3," etc.


I've been on Google all morning and I can't figure out how to display the value.  The value is added to the response object sent to the client and it seems to happen after the ASP script is completed so I can't do it server

side.   I haven't been able to find anything with client side JavaScript

about viewing header information.






The custom http headers are meant for the client [browser], not for the ASP engine.  In fact, from what I can tell, asp.dll or aspnet_isapi.dll doesn't have access to the custom header set up in IIS (except using ADSI/WMI, but that's different).  It's not in the ServerVariables collection since the ServerVariables collection just contains what was received from the client.


Check out the bottom tip here:


"As you may know, you can use the AddHeader method of the Response object to add custom http headers to your Web pages, but there's a "feature" you should be aware of when you do so. 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, so such an approach simply won't work! "


Here is another good reference:



The kicker is this:

"You can retrieve the header if a special client returns it to the server on the next request"


I caught Steve Schofield by IM and he gave me this information from the IIS



"You can use this property to send a custom HTTP header from the Web server to the client browser. Custom headers can be used to send instructions from the Web server to the client browser that are not yet supported in the current HTTP specification, such as newer HTTP headers that IIS may not inherently support at the time of the product's release. For example, you can use a custom HTTP header to allow the client browser to cache the page but prevent proxy servers from caching the page."


Both Steve and I set up some tests and confirmed this.  A network capture confirms that the header is sent back to the client.


It's a matter of order of operation.  The ISAPI Filters (which asp and run as) appear to be higher on list than when IIS appends the header.  Basically IIS adds the header on the way "out," not "in."


Further on this, if the client [browser] sends a custom header, it needs to be prefixed with HTTP_ to retrieve it within ASP(.NET).


It appears from the Microsoft link above that it's possible to receive the header from the client and send back to the server on the 2nd page view.  I tested using a POST and GET but neither appeared to work for me.  I assume that it doesn't happen automatically with IE and would require a custom client tool to handle this.


JavaScript should be able to get this because JavaScript runs after IIS added the header.


So, in summary, HTTP custom headers can't be used within ASP for any type of logic.  It's something used for the Client and not the Server.


Scott Forsyth

Microsoft MVP - ASP/ASP.NET

ASPInsider Member - MCP

Powerful Web Hosting Solutions

#1 in Service and Support 


Steve Schofield


Microsoft MVP - ASP.NET

  • if I ever plan to interrogate the ServerVariables collection, expecting to find a custom header you created in this way.are you sure?