2

I have to do if user's browser compatibility is on then need to show message to user that your browser's compatibility is on.

I have searched this a lot on google but yet not found a proper answer.

I have tried below code but HttpContext.Current.Request.UserAgent always contains MSIE 7.0

string isOn = string.Empty;

if (HttpContext.Current.Request.UserAgent.IndexOf("MSIE 7.0") > -1)
{
 isOn  = "IE8 Compatibility View";`   

    }
    else
    {
    isOn  = "IE8";
    }

}
user2078643
  • 95
  • 1
  • 2
  • 12
  • possible duplicate of [Differentiate IE7 browser and browser in IE7 compatibility mode](http://stackoverflow.com/questions/10213639/differentiate-ie7-browser-and-browser-in-ie7-compatibility-mode) – Curtis Sep 10 '14 at 08:45
  • is there any way to find that compatibility is on or not – user2078643 Sep 10 '14 at 09:01

1 Answers1

0

You may try like this

if (Request.Browser.Type.ToUpper().Contains("IE"))
{
    if (Request.Browser.MajorVersion  < 7)
    { 
        //Show the message here
    }
    ...
}
else if (Request.Browser.Type.Contains("Firefox")) 
{
   //code to show message
}
else if (Request.Browser.Type.Contains("Chrome")) 
{
   //code to show message
}

Also check this MSDN which has its own way of detecting the browser

Query the Browser property, which contains an HttpBrowserCapabilities object. This object gets information from the browser or client device during an HTTP request, telling your application the type and level of support the browser or client device offers. The object in turn exposes information about browser capabilities using strongly typed properties and a generic name-value dictionary.

private void Button1_Click(object sender, System.EventArgs e)
{
    System.Web.HttpBrowserCapabilities browser = Request.Browser;
    string s = "Browser Capabilities\n"
        + "Type = "                    + browser.Type + "\n"
        + "Name = "                    + browser.Browser + "\n"
        + "Version = "                 + browser.Version + "\n"
        + "Major Version = "           + browser.MajorVersion + "\n"
        + "Minor Version = "           + browser.MinorVersion + "\n"
        + "Platform = "                + browser.Platform + "\n"
        + "Is Beta = "                 + browser.Beta + "\n"
        + "Is Crawler = "              + browser.Crawler + "\n"
        + "Is AOL = "                  + browser.AOL + "\n"
        + "Is Win16 = "                + browser.Win16 + "\n"
        + "Is Win32 = "                + browser.Win32 + "\n"
        + "Supports Frames = "         + browser.Frames + "\n"
        + "Supports Tables = "         + browser.Tables + "\n"
        + "Supports Cookies = "        + browser.Cookies + "\n"
        + "Supports VBScript = "       + browser.VBScript + "\n"
        + "Supports JavaScript = "     + 
            browser.EcmaScriptVersion.ToString() + "\n"
        + "Supports Java Applets = "   + browser.JavaApplets + "\n"
        + "Supports ActiveX Controls = " + browser.ActiveXControls 
              + "\n"
        + "Supports JavaScript Version = " +
            browser["JavaScriptVersion"] + "\n";

    TextBox1.Text = s;
}
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331