UserAgent为您提供有关浏览器的原始字符串。它可能看起来像这样:
用户代理 :: Mozilla/4.0(兼容;MSIE 6.0b;Windows NT 5.1;.NET CLR 1.0.2914)
Request.Browser将为您提供 HttpBrowserCapabilities 对象,该对象将包含浏览器版本信息以及有关浏览器功能的一些额外信息。例如:
- 浏览器是否支持 Frames
- 如果它支持cookies?
- 支持 JavaScript 吗?
- 支持 Java 小程序 ? 等等
看下面的示例代码:
HttpBrowserCapabilities bc = 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>");
为了将浏览器版本与用户代理进行比较,您必须使用字符串操作(包含),而如果Request.Browser
您可以与属性进行比较。