Name
Headers
Synopsis
NameValueCollection = Request.Headers
The
Headers collection returns an
instance of the NameValueCollection
class
containing all HTTP headers sent with the current request. This
collection provides the same information that is returned by calling
the Request.ServerVariables collection with the
ALL_HTTP
key.
Parameters
-
NameValueCollection
An Object variable of type NameValueCollection.
Example
The example writes the HTTP headers passed with the request to the browser, first by using the ServerVariables(“ALL_HTTP”) method and then by using the Headers collection:
Sub Page_Load( ) Dim AllHttp As String ' Get a String with all the HTTP headers AllHttp = Request.ServerVariables("ALL_HTTP") ' Use Replace to format the String AllHttp = Replace(AllHttp, "HTTP", "<br/>HTTP" Message.Text &= AllHttp & "<br/><br/>" Dim Counter1, Counter2 As Integer Dim Keys(), subKeys( ) As String Dim HeaderColl As NameValueCollection ' Load Headers into NameValueCollection HeaderColl=Request.Headers ' Get keys into an array Keys = HeaderColl.AllKeys For Counter1 = 0 To Keys.GetUpperBound(0) Message.Text &= "Key: " & Keys(Counter1) & "<br/>" ' Get all values under this key subKeys = HeaderColl.GetValues(Counter1) For Counter2 = 0 To subKeys.GetUpperBound(0) Message.Text &= "Value " & CStr(Counter2) & ": " & _ subKeys(Counter2) & "<br/>" Next Counter2 Next Counter1 End Sub
Notes
The Headers collection returns only the HTTP headers that were sent as a part of the current request, as opposed to ...
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.