Internet Explorer Browser Detection Issues

I have Getaway in my MVC3 application in layout:

@if ((Request.Browser.Browser == "IE") && ((Request.Browser.MajorVersion == 7))) { //show some content } else { //show another content } 

I have many users complain (users with Internet Explorer 8). They see the contents of Internet Explorer 7 from my application. What happened to my way to discover the version of Internet Explorer 7? How can I be sure that the user has 100% version of Internet Explorer 7 in my application? Maybe this is a specific OS problem?

+4
source share
2 answers

The problem is that the HttpBrowserCapabilities class aka Request.Browser parses the userAgent header from the request, which contains information about the client (in your case the browser), which may not always be 100% reliable, since user agents change easily.

If you know what MajorVersion value MajorVersion returned, and enough is enough, you can put a fix for it. Alternatively, you can try checking browsers below IE8 (again, but not 100%), for example.

 @if ((Request.Browser.Browser == "IE") && ((Request.Browser.MajorVersion < 8))) { //show IE7 content } else { //show IE8+ content } 
+13
source

The version number must be specific to IE.

  if (Request.Browser.Browser == "IE" && Request.Browser.Version == "7.0") { //Show IE 7 content } else { // Show other than IE7 content } 
+3
source

Source: https://habr.com/ru/post/1206891/


All Articles