ASP.Net/Request/HTTP Header
Содержание
Displaying the HTTP headers collection in ASP.NET with for loop
<source lang="csharp">
<%@ Page Language="vb" %> <html>
<head> <title>Displaying the HTTP headers collection in ASP.NET</title> </head>
<body>
<%
Dim HostAddress, HostName, Languages() As String
Dim iCounter As Integer
HostAddress = Request.UserHostAddress
HostName = Request.UserHostName
Languages = Request.UserLanguages
Response.Write("Client IP Address: " & HostAddress & "
")
Response.Write("Client Machine Name: " & HostName & "
")
For iCounter = 0 To Languages.GetUpperBound(0)
Response.Write("Client Language " & iCounter & ": " & CStr(Languages(iCounter)) & "
")
Next iCounter
%>
</body> </html>
</source>
Displaying the HTTP headers collection in ASP.NET with "select case statement"
<source lang="csharp">
<%@ Page Language="vb" %> <html>
<head> <title>Displaying the HTTP headers collection in ASP.NET</title> </head>
<body>
<%
Select Case Request.HttpMethod
Case "POST"
Response.Write("POST requests not allowed!
")
Response.End
Case "HEAD"
Response.Write("HEAD requests not allowed!
")
Response.End
Case "GET"
"Process request
Response.Write("GET requests are allowed!
")
Case Else
Response.Write("Unknown request: not allowed!
")
Response.End
End Select
%>
</body> </html>
</source>
Output HTTP Header (VB.net)
<source lang="csharp">
<%@ Page Language=VB Debug=true %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
Dim I As IntegerlblMessage1.Text = "
" & Request.Headers.GetKey(I) _ & " | " & Request.Headers(I) _ & " |
End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Headers Sample Page</TITLE> </HEAD> <BODY > <form runat="server"> <asp:Label
id="lblMessage1" runat="Server" Font-Bold="True"
/> </Form> </BODY> </HTML>
</source>
Showing HTTP Headers via the Headers Collection in ASP.NET
<source lang="csharp">
<%@ Page Language="vb" %> <html>
<head> <title>Showing HTTP Headers via the Headers Collection in ASP.NET</title> </head>
<body>
<%
Dim AllHttp As String
AllHttp = Request.ServerVariables("ALL_HTTP")
AllHttp = Replace(AllHttp, "HTTP", "
HTTP")
Response.Write(AllHttp & "
")
Dim Counter1, Counter2 As Integer
Dim Keys(), subKeys() As String
Dim HeaderColl As NameValueCollection
HeaderColl=Request.Headers
Keys = HeaderColl.AllKeys
For Counter1 = 0 To Keys.GetUpperBound(0)
Response.Write("Key: " & Keys(Counter1) & "
") subKeys = HeaderColl.GetValues(Counter1) " Get all values under this key. For Counter2 = 0 To subKeys.GetUpperBound(0) Response.Write("Value " & CStr(Counter2) & ": " & subKeys(Counter2) & "
") Next Counter2
Next Counter1 %>
</body> </html>
</source>