0

My code is:

protected void btn_log_Click(object sender, EventArgs e)
    {
     System.Web.HttpBrowserCapabilities browser = Request.Browser;
     string opSystem = browser.Platform;
     string browserName = browser.Browser;
     string Version = browser.Version;
    }

My problem: i am getting the IE11 Version as 0.00 and browser name as Mozilla

karthik
  • 1
  • 2
  • i am getting the IE11 Version as 0.00 and browser name as Mozilla – karthik Mar 13 '19 at 09:56
  • it likely depends what user-agent string the browser is actually sending. This is easily spoofed – ADyson Mar 13 '19 at 10:16
  • Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko how to decode this user - agent string.i want version name – karthik Mar 13 '19 at 12:14
  • "Trident" is the Internet Explorer rendering engine, so this gives you the clue. The reason it identifies as Mozilla is [buried in ancient browser wars history](https://stackoverflow.com/questions/5125438/why-do-chrome-and-ie-put-mozilla-5-0-in-the-user-agent-they-send-to-the-server) – ADyson Mar 13 '19 at 12:16
  • P.S. The list of possible user-agent strings is large (https://developers.whatismybrowser.com/useragents/explore/) and theoretically infinite so I'd think you're probably best looking for patters and keywords rather than trying to list them all. P.S. Are you just trying to log usage by different browsers? Because your IIS logs can do that for you already. If you're intending to change how your application behaves depending on the browser, that's a bit 2000s-era for my liking. And if it's truly necessary to vary something it's almost certainly better done on the client-side through JS and CSS – ADyson Mar 13 '19 at 12:21
  • There shouldn't be much you need to do differently for IE11 though – ADyson Mar 13 '19 at 12:24

2 Answers2

0

You could try to get the browser version from UserAgent. Code like this:

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

Label1.Text = userBrowser.Browser + "--" + userBrowser.Version;

Here is an article about how to detect browsers in ASP.NET with browser files, you can also check it.

Besides, I think you could also detect the browser version using JavaScript, you could check this article.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
0
 html
      <input id="lblver" type="hidden" runat="server" />  

 java script
  <script type="text/javascript">
  var rv = -1;
  var lblver = '<%= lblver.ClientID %>';
  if (navigator.appName == 'Microsoft Internet Explorer') {
      var ua = navigator.userAgent;
      var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
      rv = parseFloat(RegExp.$1);
  }
  else if (navigator.appName == 'Netscape') {
      var ua = navigator.userAgent;
      var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
          rv = parseFloat(RegExp.$1);
  }
  document.getElementById(lblver).value = rv;
  </script>

 c# code
 Version = lblver.Value;
karthik
  • 1
  • 2