【问题标题】:Get client browser version in C# (When IE Compatibility mode enabled)在 C# 中获取客户端浏览器版本(启用 IE 兼容模式时)
【发布时间】:2015-05-02 11:07:59
【问题描述】:

我们需要从 C# 代码中知道客户端的浏览器版本。我们使用 Request.Browser 或 HTTP_USER_AGENT 来获取详细信息。但是,在 IE 中,当启用兼容模式时,它总是返回 IE 7 版本,而与 IE 的版本无关。即,即使在启用兼容模式的 IE 11 中,它也会返回 IE 7,但我想要的是 IE 11 的实际版本。有什么方法可以获得实际的 IE 版本?

【问题讨论】:

  • 嗨:正如我之前提到的,我需要 C#(服务器端)而不是客户端中的信息。
  • 浏览器版本嗅探现在非常不受欢迎。相反,建议使用嗅探功能。
  • 我说的是服务器端。不是 JavaScript。
  • 看起来您的问题被标记为 JS,标签垃圾邮件?

标签: c# html asp.net internet-explorer


【解决方案1】:

我认为这是对你最好的帮助。

protected void Page_Load(object sender, EventArgs e) {

        var userAgent = HttpContext.Current.Request.UserAgent;
        var userBrowser = new HttpBrowserCapabilities
        {
            Capabilities = new Hashtable
            {
                {
                    string.Empty, userAgent
                }
            }
        };

        var factory = new BrowserCapabilitiesFactory();
        factory.ConfigureBrowserCapabilities(
            new NameValueCollection(), userBrowser);




        //Set User browser Properties
        var BrowserBrand = userBrowser.Browser;
        var BrowserVersion = userBrowser.Version;


        Response.Write("browser brand :- " + BrowserBrand + "<br/>");
        Response.Write("browser version :- " + BrowserVersion + "<br/>");



    }

【讨论】:

    【解决方案2】:

    在Page_load中写下这个

    HttpBrowserCapabilities brObject = Request.Browser;
    
    Response.Write("Browser Type: "+ brObject.Type);
    Response.Write("<p>"+"Browser Version: "+ brObject.Version);
    

    【讨论】:

    • 他就是这么用的。
    • 这是尝试过的。但不适用于兼容模式。
    • 我已经尝试过这段代码并为我工作“Request.Browser.Browser”给出了 Internet Explorer,“Request.MajorVersion”给出了 11,这是我当前的浏览器版本
    • 您是否启用了兼容模式?当您启用此功能时,即使是 IE 11 , Request.MajorVersion 也会为您提供 7 NOT 11
    【解决方案3】:

    我们找到了解决方案。 HTTP_USER_AGENT 将包含可用于此目的的“Trident”值。每个版本的 IE 包含不同的 Trident 版本值,如 Trident 5.0、Trident 6.0 等,可用于识别 IE 版本。

    【讨论】:

      猜你喜欢
      • 2013-04-23
      • 1970-01-01
      • 2013-10-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      相关资源
      最近更新 更多