SP中的Browser Capbilities组件嫩构获取更深层次的浏览器信息,ASP.NET中的Browser对象可以认为是Browser Capabilities组件的升级版本,只是ASP.NET中的Browser对象是通过调用Request的Browser属性直接获取的。
常用的Browser对象 Request.Browser.Browser <--> 检测浏览器的类型
Request.Browser.Version <--> 检测浏览器的版本
Request.Browser.ActiveXControls <--> 检测浏览器是否支持ActiveX插件
Request.Browser.Cookies <--> 检测浏览器是否支持Cookies
Request.Browser.VBScript <--> 检测浏览器是否支持VBSCRIPT
运行以下代码可以看到所有Browser对象,请配合观察源代码
引用内容
<html> <head> <script runat="server" language="c#"> public void Page_Load(Object Source, EventArgs E) { HttpBrowserCapabilities bc= Request.Browser;
Welcome.Text = "您好,您正在使用 " + bc.Browser + " v." + bc.Version + ",你的运行平台是 " + bc.Platform ;
ActiveXControls.Text = bc.ActiveXControls.ToString(); AOL.Text = bc.AOL.ToString(); BackgroundSounds.Text = bc.BackgroundSounds.ToString(); Beta.Text = bc.Beta.ToString(); Browser.Text = bc.Browser.ToString(); CDF.Text = bc.CDF.ToString(); Cookies.Text = bc.Cookies.ToString(); Crawler.Text = bc.Crawler.ToString();
Frames.Text = bc.Frames.ToString(); JavaApplets.Text = bc.JavaApplets.ToString(); JavaScript.Text = bc.JavaScript.ToString(); MajorVersion.Text = bc.MajorVersion.ToString(); MinorVersion.Text = bc.MinorVersion.ToString(); Platform.Text = bc.Platform.ToString(); Tables.Text = bc.Tables.ToString(); Type.Text = bc.Type.ToString(); VBScript.Text = bc.VBScript.ToString(); Version.Text = bc.Version.ToString(); Win16.Text = bc.Win16.ToString(); Win32.Text = bc.Win32.ToString(); } </script> <style> body{font-size:9pt} td{font-size:9pt} </style> </head> <body> <form runat="server" method="post"> 您的浏览器信息已经完全在我们的掌握中了^&^:<br> <asp:Label runat="server" id="Welcome" Font-Bold="True" /> <table border="1" width="400" bordercolor="black"> <tr bgcolor="skyblue"> <td width="50%"><b>浏览器属性<b></td> <td width="50%"><b>检测结果<b></td> </tr> <tr > <td width="50%">ActiveXControls:</td> <td width="50%"><asp:Label runat="server" id="ActiveXControls" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">AOL:</td> <td width="50%"><asp:Label runat="server" id="AOL" /></td> </tr> <tr > <td width="50%">BackgroundSounds:</td> <td width="50%"><asp:Label runat="server" id="BackgroundSounds" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Beta:</td> <td width="50%"><asp:Label runat="server" id="Beta" /></td> </tr> <tr > <td width="50%">Browser:</td> <td width="50%"><asp:Label runat="server" id="Browser" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">CDF:</td> <td width="50%"><asp:Label runat="server" id="CDF" /></td> </tr> <tr > <td width="50%">Cookies:</td> <td width="50%"><asp:Label runat="server" id="Cookies" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Crawler:</td> <td width="50%"><asp:Label runat="server" id="Crawler" /></td> </tr> <tr> <td width="50%">Frames:</td> <td width="50%"><asp:Label runat="server" id="Frames" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">JavaApplets:</td> <td width="50%"><asp:Label runat="server" id="JavaApplets" /></td> </tr> <tr> <td width="50%">JavaScript:</td> <td width="50%"><asp:Label runat="server" id="JavaScript" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">MajorVersion:</td> <td width="50%"><asp:Label runat="server" id="MajorVersion" /></td> </tr> <tr> <td width="50%">MinorVersion:</td> <td width="50%"><asp:Label runat="server" id="MinorVersion" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Platform:</td> <td width="50%"><asp:Label runat="server" id="Platform" /></td> </tr> <tr> <td width="50%">Tables:</td> <td width="50%"><asp:Label runat="server" id="Tables" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Type:</td> <td width="50%"><asp:Label runat="server" id="Type" /></td> </tr> <tr> <td width="50%">VBScript:</td> <td width="50%"><asp:Label runat="server" id="VBScript" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Version:</td> <td width="50%"><asp:Label runat="server" id="Version" /></td> </tr> <tr> <td width="50%">Win16:</td> <td width="50%"><asp:Label runat="server" id="Win16" /></td> </tr> <tr bgcolor="skyblue"> <td width="50%">Win32:</td> <td width="50%"><asp:Label runat="server" id="Win32" /></td> </tr> </table> </form> </body> </html>