1

I am trying to determine the browser and the version in which our user is accessing our application using the below code:

public bool MyBrowser(HttpRequestBase request)
    {
        HttpBrowserCapabilitiesBase browser = request.Browser;
        switch (browser.Browser)
        {
            case "IE":
                {
                    if (browser.MajorVersion < 6)
                        //do something
                }
            case "Firefox":
                {
                    if (browser.MajorVersion < 3)
                        //do something
                }
            case "AppleMAC-Safari":
                {
                    if (request.UserAgent.Contains("Chrome") || browser.MajorVersion < 4)
                        return false;
                    return true;

                }

            default: return false;
       }
 }

This code is always returning false when user opens the site in IE11, this piece was working fine until we migrated to IE11. What could be the reason why this is happening. Please suggest if there is a workaround.

TRR
  • 1,637
  • 2
  • 26
  • 43
  • Did you check this answers: http://stackoverflow.com/questions/19999989/internet-explorer-11-detection-on-server-side – HABJAN Mar 25 '15 at 10:17
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Mar 25 '15 at 10:19

1 Answers1

0

You could use a function similar to the one below to detect IE11. It returns 0 for non-IE browsers.

 
function ie_ver() {
  var iev = 0;
  var ieold = (/MSIE (\d+\.\d+);/.test(navigator.userAgent));
  var trident = !!navigator.userAgent.match(/Trident\/7.0/);
  var rv = navigator.userAgent.indexOf("rv:11.0");

  if (ieold) iev = new Number(RegExp.$1);
  if (navigator.appVersion.indexOf("MSIE 10") != -1) iev = 10;
  if (trident && rv != -1) iev = 11;

  return iev;
}


alert(ie_ver())
Alex
  • 21,273
  • 10
  • 61
  • 73
  • Agree that the above code works, But I have lot of browser to check. I would prefer to do it in the code behind. Thanks! – TRR Mar 25 '15 at 11:46
  • 1
    You can also check if the UserAgent containts Trident in the code behind, for example: if (request.UserAgent.Contains("Trident")) { //IE11} – Alex Mar 25 '15 at 11:49