ASP.Net/Request/HTTP Header — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

Displaying the HTTP headers collection in ASP.NET with for loop

<%@ Page Language="vb" %>
<html>
   <head>
      <title>Displaying the HTTP headers collection in ASP.NET</title>
   </head>
<body>
<p>
<%
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 & "<br>")
Response.Write("Client Machine Name: " & HostName & "<br>")
For iCounter = 0 To Languages.GetUpperBound(0)
   Response.Write("Client Language " & iCounter & ": " & CStr(Languages(iCounter)) & "<br>")
Next iCounter
%>
</p>
</body>
</html>



Displaying the HTTP headers collection in ASP.NET with "select case statement"

<%@ Page Language="vb" %>
<html>
   <head>
      <title>Displaying the HTTP headers collection in ASP.NET</title>
   </head>
<body>
<p>
<%
Select Case Request.HttpMethod
   Case "POST"
      Response.Write("POST requests not allowed!<br>")
      Response.End
   Case "HEAD"
      Response.Write("HEAD requests not allowed!<br>")
      Response.End
   Case "GET"
      "Process request
      Response.Write("GET requests are allowed!<br>")
   Case Else
      Response.Write("Unknown request: not allowed!<br>")
      Response.End      
End Select
%>
</p>
</body>
</html>



Output HTTP Header (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    Dim I As Integer
    lblMessage1.Text = "<Table>"
    For I = 0 To Request.Headers.Count - 1
        lblMessage1.Text = lblMessage1.Text _
            & "<TR><TD><B>" & Request.Headers.GetKey(I) _
            & "</B></TD><TD>" & Request.Headers(I) _
            & "</TD></TR>"
    Next
    lblMessage1.Text = lblMessage1.Text & "</Table>"
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Headers Sample Page</TITLE>
</HEAD>
<BODY >
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage1"
    runat="Server"
    Font-Bold="True"
/>
</Font>
</Form>
</BODY>
</HTML>



Showing HTTP Headers via the Headers Collection in ASP.NET

<%@ 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", "<br>HTTP")
Response.Write(AllHttp & "<br>")
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) & "<br>")
   subKeys = HeaderColl.GetValues(Counter1) " Get all values under this key.
   For Counter2 = 0 To subKeys.GetUpperBound(0)
      Response.Write("Value " & CStr(Counter2) & ": " & subKeys(Counter2) & "<br>")
   Next Counter2
Next Counter1
%>

</body>
</html>