查詢 Browser 屬性,
該屬性包含一個 HttpBrowserCapabilities 對象。
在 HTTP 請求過程中,該對象會從浏覽器或客戶端設備中獲取信息,
以便讓您的應用程序知道浏覽器或客戶端設備提供的支持類型和級別。
該對象隨後使用強類型屬性和泛型名稱值字典公開有關浏覽器功能的信息。
下面的代碼示例演示如何在頁上的文本框中顯示浏覽器信息。
=======
Visual Basic
=======
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = ""
With Request.Browser
s &= "Browser Capabilities" & vbCrLf
s &= "Type = " & .Type & vbCrLf
s &= "Name = " & .Browser & vbCrLf
s &= "Version = " & .Version & vbCrLf
s &= "Major Version = " & .MajorVersion & vbCrLf
s &= "Minor Version = " & .MinorVersion & vbCrLf
s &= "Platform = " & .Platform & vbCrLf
s &= "Is Beta = " & .Beta & vbCrLf
s &= "Is Crawler = " & .Crawler & vbCrLf
s &= "Is AOL = " & .AOL & vbCrLf
s &= "Is Win16 = " & .Win16 & vbCrLf
s &= "Is Win32 = " & .Win32 & vbCrLf
s &= "Supports Frames = " & .Frames & vbCrLf
s &= "Supports Tables = " & .Tables & vbCrLf
s &= "Supports Cookies = " & .Cookies & vbCrLf
s &= "Supports VBScript = " & .VBScript & vbCrLf
s &= "Supports JavaScript = " & _
.EcmaScriptVersion.ToString() & vbCrLf
s &= "Supports Java Applets = " & .JavaApplets & vbCrLf
s &= "Supports ActiveX Controls = " & .ActiveXControls & _
vbCrLf
End With
TextBox1.Text = s
End Sub
=====
C#
=====
private void Button1_Click(object sender, System.EventArgs e)
{
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string s = "Browser Capabilities<br />"
+ "Type = " + browser.Type + "<br />"
+ "Name = " + browser.Browser + "<br />"
+ "Version = " + browser.Version + "<br />"
+ "Major Version = " + browser.MajorVersion + "<br />"
+ "Minor Version = " + browser.MinorVersion + "<br />"
+ "Platform = " + browser.Platform + "<br />"
+ "Is Beta = " + browser.Beta + "<br />"
+ "Is Crawler = " + browser.Crawler + "<br />"
+ "Is AOL = " + browser.AOL + "<br />"
+ "Is Win16 = " + browser.Win16 + "<br />"
+ "Is Win32 = " + browser.Win32 + "<br />"
+ "Supports Frames = " + browser.Frames + "<br />"
+ "Supports Tables = " + browser.Tables + "<br />"
+ "Supports Cookies = " + browser.Cookies + "<br />"
+ "Supports VBScript = " + browser.VBScript + "<br />"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "<br />"
+ "Supports Java Applets = " + browser.JavaApplets + "<br />"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "<br />";
Response.Write(s);
}