ASP.NET 4.0 Website Fix for IE 11

OK. This article ASP.NET 4.0 Website Fix for IE 11 will show you how to fix your websites that break in IE 11.  This is for anyone that has discovered the new IE 11 User Agent String issue. This is for all web sites, applications. projects that are targeted at the ASP.NET 4.0 framework. The main issue is the new IE 11 User Agent and the bug in the 4.0 framework. I will describe what the issues is and then show the fix. It is easier than upgrading your web server and all of your ASP.NET applications up to the 4.5 framework. The 4.5 framework has the user agent string bug fixed. So here is the details:

First there is a bug in the ASP.NET 4.0 framework when it reads the User Agent Strings. Here is the article talking about this issue from Scott Hanselman:

The bug causes the Post Back functions to not work. So when trying to view our ASP.NET 4.0 website in IE 11 our site would not work. All of our Post Back functionality was gone. So I tried using the Microsoft magic line of code to fix this issue by forcing IE to emulate IE10.

Microsoft Magic Line of Code: <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE10″/>

Well this did not work. It forced IE11 to display site in IE10 mode but it kept the User Agent String as Default which would break the site. I then opened up IE 11 Developer Tools and then switched the User Agent String to IE 10 and BOOM, Goes the Dynamite! It worked. The site Post Back functionality is working. So I knew something was wrong. It would force IE to go to whatever IE version I chose, but it kept the User Agent String at Default, thus breaking the website. Image 1 shows dev tools and the website in IE 10 with User Agent String as default breaking the website.



image 2 show dev tools and the website in IE 10 and me manually changing the User String Agent to IE 10 and the website works.




So after many hours of research, I found out that Microsoft changed the IE 11 User Agent String. This caused IE 11 to stay at Default for User Agent String because it has been confused by the change. It is what I found out about the new IE 11 User Agent String: This is from the Microsoft website:

Here is the user agent string from IE 11 on a Windows 8.1 machine: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko

IE 11 on Windows 7 machine: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko

Older IE 10 Use Agent String Version: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)

IE 9 User Agent String Version:

See in the past, to identify Internet Explorer just search for the string “MSIE” in the user-agent string. If present, the browser is Internet Explorer. Now that is gone in IE 11. Also they added ‘Mozilla’ and ‘like Gecko’ in IE 11 User Agent String. This sounds like a Firefox browser.

Here is the link from Microsoft about the IE 11 changes:

OK. Anyway enough about the issue. How the heck do we fix this. One fix that I read was to upgrade from the ASP.NET 4.0 framework to the 4.5 framework. I figured out an easier way around this. OK, we need to create an ASP.NET folder named, App_Browsers. This ASP.NET folder is the one most unknown. Here is a link to read more about the App_Browsers folder:

Now we just add a file with the extension .browser in this folder. Place this code in the file and save. Restart your IIS server and it works.

  <browser id="IE11" parentID="Mozilla">
      <useragent match="Trident\/7.0; rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)"></useragent>
      <useragent nonMatch="IEMobile"></useragent>
      <useragent match="Trident/(?'layoutVersion'\d+)"></useragent>
      <capability name="browser"              value="IE"></capability>
      <capability name="layoutEngine"         value="Trident"></capability>
      <capability name="layoutEngineVersion"  value="${layoutVersion}"></capability>
      <capability name="extra"                value="${extra}"></capability>
      <capability name="isColor"              value="true"></capability>
      <capability name="letters"              value="${letters}"></capability>
      <capability name="majorversion"         value="${major}"></capability>
      <capability name="minorversion"         value="${minor}"></capability>
      <capability name="screenBitDepth"       value="8"></capability>
      <capability name="type"                 value="IE${major}"></capability>
      <capability name="version"              value="${version}"></capability>
  <!-- Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11,0) like Gecko -->
  <browser id="IE110" parentID="IE11">
      <capability name="majorversion" match="11"></capability>
      <capability name="ecmascriptversion"    value="3.0"></capability>
      <capability name="jscriptversion"       value="5.6"></capability>
      <capability name="javascript"           value="true"></capability>
      <capability name="javascriptversion"    value="1.5"></capability>
      <capability name="msdomversion"         value="${majorversion}.${minorversion}"></capability>
      <capability name="w3cdomversion"        value="1.0"></capability>
      <capability name="ExchangeOmaSupported" value="true"></capability>
      <capability name="activexcontrols"      value="true"></capability>
      <capability name="backgroundsounds"     value="true"></capability>
      <capability name="cookies"              value="true"></capability>
      <capability name="frames"               value="true"></capability>
      <capability name="javaapplets"          value="true"></capability>
      <capability name="supportsCallback"     value="true"></capability>
      <capability name="supportsFileUpload"   value="true"></capability>
      <capability name="supportsMultilineTextBoxDisplay" value="true"></capability>
      <capability name="supportsMaintainScrollPositionOnPostback" value="true"></capability>
      <capability name="supportsVCard"        value="true"></capability>
      <capability name="supportsXmlHttp"      value="true"></capability>
      <capability name="tables"               value="true"></capability>
      <capability name="supportsAccessKeyAttribute"    value="true"></capability>
      <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter"></capability>
      <capability name="vbscript"             value="true"></capability>



Here is the link where I found this nice piece of code:

ASP.NET, Blog, Web Design, Web Development,