gpt4 book ai didi

c# - Request.UserAgent 和 Request.Browser 有什么区别?

转载 作者:太空狗 更新时间:2023-10-29 17:32:51 27 4
gpt4 key购买 nike

下面是我的代码:

    User_Info.Add(!string.IsNullOrEmpty(Request.UserAgent) ? Request.UserAgent : string.Empty);//4:UserAgent

HttpBrowserCapabilities browser = Request.Browser;
User_Info.Add(!string.IsNullOrEmpty(browser.Browser) ? "Name : " + browser.Browser + " | " +
"Type : " + browser.Type + " | " +
"MajorVersion : " + browser.MajorVersion + " | " +
"MinorVersion : " + browser.MinorVersion : string.Empty);//5:UserBrowser

Request.UserAgent 和 Request.Browser 有什么区别?
我无法理解那些 UserAgent 字符串!
你能举一些例子和解释吗?

最佳答案

UserAgent给你一个关于浏览器的原始字符串。它可能看起来像这样:

User Agent :: Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1; .NET CLR 1.0.2914)

Request.Browser将为您提供 HttpBrowserCapabilities 对象,该对象将包含浏览器版本信息以及有关浏览器功能的一些额外信息。例如:

  1. 浏览器是否支持框架
  2. 是否支持 cookie?
  3. 支持 JavaScript?
  4. 支持 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 的情况下,您可以与属性进行比较。

关于c# - Request.UserAgent 和 Request.Browser 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10780418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com