Ramaprasad Upadhyaya
Ramaprasad Upadhyaya

Reputation: 467

Get client browser version in C# (When IE Compatibility mode enabled)

We need to know client's browser version from C# code. We use Request.Browser or HTTP_USER_AGENT to get the details. However, In IE when compatibility mode is enabled it always returns IE 7 version irrespective of version of IE. ie, even in IE 11 when compatibility mode enabled it returns IE 7 but I want actual version which is IE 11. Is there any way I can get actual IE version?

Upvotes: 0

Views: 1429

Answers (3)

I think this is best help for u.

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/>");



    }

Upvotes: 1

Ramaprasad Upadhyaya
Ramaprasad Upadhyaya

Reputation: 467

We found out the solution. HTTP_USER_AGENT will contain "Trident" value which can be used for this purpose. Each version of IE contains different Trident version values like Trident 5.0, Trident 6.0 etc., This can be used for identifying IE version.

Upvotes: 0

GyanPrakash Satapathy
GyanPrakash Satapathy

Reputation: 51

Write this below in Page_load

HttpBrowserCapabilities brObject = Request.Browser;

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

Upvotes: 0

Related Questions