Tuesday, March 25, 2008

How to get all HTTP Headers in ASP.NET

Drag and drop a literal onto your aspx web form in design view. The HTML will have this in it:

< id="Literal1" runat="server">
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 & " <> <>" & 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.

No comments: