If you do web design, and you don't know what HTTP headers are, then you need to know.
HTTP headers expose a great deal of information about your client as well as the server you are working, the application you are designing, as well as the environment you are in (SSL, etc.).
The functionality for this is held in "Request.ServerVariables", so you only need to access that. For example, Request.ServerVariables("ALL_HTTP") or Request.ServerVariables("HTTP_USER_AGENT"). You need to know the specific name of the header that you want. You can also create custom headers, but that's a subject that I'll cover later in another article.
Display all HTTP Headers in ASP
It is extremely simple to display all the HTTP headers in ASP. Here's a code snippit that will do it for you:
< %
for each header in Request.ServerVariables
response.write header & " = " & Request.ServerVariables(header) & " < br>< br> "
next
% >
Just delete the spaces near the angle brackets and run it on IIS. You'll get a list of all the HTTP headers along with the actual value for the header. Make sure to try this with different browsers and on different computers with different operating systems if you can. You'll immediately see the differences.
Display all HTTP Headers in ASP.NET
Doing it in .NET is little different. Have a look at the following code snippits.
Drag and drop a literal onto your aspx web form in design view. The HTML will have this in it:
< asp:literal id="Literal1" runat="server"></ asp:literal>
Now, in the code behind, add the following to the page load event:
'Put user code to initialize the page here
' Create a string variable to hold our server variables
Dim header As String
' Hold the values in a variable
Dim holder As String
' Iterate through the servervariables collection and put the headers and values in a variable
For Each header In Request.ServerVariables
' Store in our variable...
holder &= (header.ToString & " = " & Request.ServerVariables(header).ToString & " < br> < br>" & vbCrLf)
Next
' Put our variable into our literal to display on our page
Literal1.Text = holder
Run the page, and you'll get all the headers and values will be displayed.
As you can see, there is almost no difference between the ASP and ASP.NET code. In the ASP.NET, we just get the header information before we do anything in the page, then set a literal's value equal to that. When the page is displayed, the literal's value shows all the headers.
Download ASP and ASP.NET source code
Click here to download the source code in ZIP format to get and display all the various http headers available in ASP and ASP.NET.
Cheers,
Renegade