ASP.NET 取得使用者及伺服器 環境變數 @ 甘蔗築夢田 :: Xuite日誌
  • 部落格觀察
  • 平均分數:0 顆星
    投票人數:0
    我要評分:
  • 關鍵字
  • 累積 | 今日
    loading......
  • 沒有新回應!
  • 就愛碎碎念
  • 2009-06-19 14:28 ASP.NET 取得使用者及伺服器 環境變數
    平均分數:0 顆星    投票人數:0
    我要評分:

    在撰寫網站程式的時候,有時候會需要依照使用者的環境狀態作一些調整,這時你必須要有方法得知使用者電腦軟體使用狀態,你就可以下面方法 ex: Request.Browser.Browser 得知使用者的瀏覽器,來變更調整你的程式動作。

    取得使用者的IP: Request.UserHostAddress

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim bc As HttpBrowserCapabilities = Request.Browser
    Response.Write("<p>Browser Capabilities:</p>")
    Response.Write("Type = " & bc.Type & "<br>")
    Response.Write("Name = " & bc.Browser & "<br>")
    Response.Write("Version = " & bc.Version & "<br>")
    Response.Write("Major Version = " & bc.MajorVersion & "<br>")
    Response.Write("Minor Version = " & bc.MinorVersion & "<br>")
    Response.Write("Platform = " & bc.Platform & "<br>")
    Response.Write("Is Beta = " & bc.Beta & "<br>")
    Response.Write("Is Crawler = " & bc.Crawler & "<br>")
    Response.Write("Is AOL = " & bc.AOL & "<br>")
    Response.Write("Is Win16 = " & bc.Win16 & "<br>")
    Response.Write("Is Win32 = " & bc.Win32 & "<br>")
    Response.Write("Supports Frames = " & bc.Frames & "<br>")
    Response.Write("Supports Tables = " & bc.Tables & "<br>")
    Response.Write("Supports Cookies = " & bc.Cookies & "<br>")
    Response.Write("Supports VB Script = " & bc.VBScript & "<br>")
    Response.Write("Supports JavaScript = " & bc.JavaScript & "<br>")
    Response.Write("Supports Java Applets = " & bc.JavaApplets & "<br>")
    Response.Write("Supports ActiveX Controls = " & bc.ActiveXControls & "<br>")
    Response.Write("CDF = " & bc.CDF & "<br>")
    Dim loop1, loop2 As Integer
    Dim arr1(), arr2() As String
    Dim coll As NameValueCollection

           ' Load ServerVariable collection into NameValueCollection object.
            coll = Request.ServerVariables
            ' Get names of all keys into a string array.

    arr1 = coll.AllKeys
    For loop1 = 0 To arr1.GetUpperBound(0)
      If Server.HtmlEncode(coll.GetValues(loop1)(0)) <> "" Then
           Response.Write("Key: _" & loop1 & "_" & arr1(loop1) & ": " & Server.HtmlEncode(coll.GetValues(loop1)(0)) & "<br>")
      End If

    'arr2 = coll.GetValues(loop1) ' Get all values under this key.
    'For loop2 = 0 To arr2.GetUpperBound(0)
    'Response.Write("Value ++" & loop2 & "++" & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)) & "<br>")

    'Next loop2
    Next loop1

    End Sub

    --- 執行的結果如下:----

    Browser Capabilities:

    Type = IE7
    Name = IE
    Version = 7.0
    Major Version = 7
    Minor Version = 0
    Platform = WinXP
    Is Beta = False
    Is Crawler = False
    Is AOL = False
    Is Win16 = False
    Is Win32 = True
    Supports Frames = True
    Supports Tables = True
    Supports Cookies = True
    Supports VB Script = True
    Supports JavaScript = True
    Supports Java Applets = True
    Supports ActiveX Controls = True
    CDF = False
    Key: _0_ALL_HTTP: HTTP_CONNECTION:Keep-Alive HTTP_ACCEPT:*/* HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:zh-tw HTTP_HOST:localhost:2788 HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) HTTP_UA_CPU:x86
    Key: _1_ALL_RAW: Connection: Keep-Alive Accept: */* Accept-Encoding: gzip, deflate Accept-Language: zh-tw Host: localhost:2788 User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) UA-CPU: x86
    Key: _3_APPL_PHYSICAL_PATH: C:\Documents and Settings\Jerry\function_test\
    Key: _4_AUTH_TYPE: NTLM
    Key: _5_AUTH_USER: WINNER\Jerry
    Key: _7_LOGON_USER: WINNER\Jerry
    Key: _8_REMOTE_USER: WINNER\Jerry
    Key: _18_CONTENT_LENGTH: 0
    Key: _28_LOCAL_ADDR: 127.0.0.1
    Key: _29_PATH_INFO: /function_test/Default.aspx
    Key: _30_PATH_TRANSLATED: C:\Documents and Settings\Jerry\function_test\Default.aspx
    Key: _32_REMOTE_ADDR: 127.0.0.1
    Key: _33_REMOTE_HOST: 127.0.0.1
    Key: _35_REQUEST_METHOD: GET
    Key: _36_SCRIPT_NAME: /function_test/Default.aspx
    Key: _37_SERVER_NAME: localhost
    Key: _38_SERVER_PORT: 2788
    Key: _39_SERVER_PORT_SECURE: 0
    Key: _40_SERVER_PROTOCOL: HTTP/1.1
    Key: _42_URL: /function_test/Default.aspx
    Key: _43_HTTP_CONNECTION: Keep-Alive
    Key: _44_HTTP_ACCEPT: */*
    Key: _45_HTTP_ACCEPT_ENCODING: gzip, deflate
    Key: _46_HTTP_ACCEPT_LANGUAGE: zh-tw
    Key: _47_HTTP_HOST: localhost:2788
    Key: _48_HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
    Key: _49_HTTP_UA_CPU: x86

    喜歡在黃昏啃甘蔗 / Xuite日誌 / 回應(0) / 引用(0) / 好文轉寄
  • 回應