ASP.NET 4.0 and IE10 and IE11

Had some problems recently with ASP.NET 4.0 and browser versions IE10 and IE11. Further digging reveals the issue relates to how ASP.NET works out the capabilities of the browser before rendering the pages. Microsoft Hotfix KB2836939 should fix the issue for most users, however, this particular server wasn't playing ball after the hotfix was applied. (Non standard browser config files? Previous Hotfix for same issue? Not sure, would love to hear from anyone else with same problem to diagnose why this happened.)

It's worth noting that I did NOT get the "__postback is undefined" error that most people see - I was simply not getting any JavaScript rendered at all (EG: with the AUTOPOSTBACK property set to true, the control wouldn't render the "onChange" attribute to trigger the postback in the browser).

ASP.NET applications do allow you to overrule the machine level settings for the browsers. I started by creating a web page to show me my browser capabilities.

Browser.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Browser.aspx.cs" Inherits="BrowserTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:literal id="litBrowser" runat="server"/>
    </div>
    </form>
</body>
</html>

With a code behind with the following in it;

Browser.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Vevo.WebUI;

public partial class BrowserTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpBrowserCapabilities bc = Request.Browser;
        litBrowser.Text += "<p>Browser Capabilities:</p>";
        litBrowser.Text +="Type = " + bc.Type + "<br>";
        litBrowser.Text +="Name = " + bc.Browser + "<br>";
        litBrowser.Text +="Version = " + bc.Version + "<br>";
        litBrowser.Text +="Major Version = " + bc.MajorVersion + "<br>";
        litBrowser.Text +="Minor Version = " + bc.MinorVersion + "<br>";
        litBrowser.Text +="Platform = " + bc.Platform + "<br>";
        litBrowser.Text +="Is Beta = " + bc.Beta + "<br>";
        litBrowser.Text +="Is Crawler = " + bc.Crawler + "<br>";
        litBrowser.Text +="Is AOL = " + bc.AOL + "<br>";
        litBrowser.Text +="Is Win16 = " + bc.Win16 + "<br>";
        litBrowser.Text +="Is Win32 = " + bc.Win32 + "<br>";
        litBrowser.Text +="Supports Frames = " + bc.Frames + "<br>";
        litBrowser.Text +="Supports Tables = " + bc.Tables + "<br>";
        litBrowser.Text +="Supports Cookies = " + bc.Cookies + "<br>";
        litBrowser.Text +="Supports VB Script = " + bc.VBScript + "<br>";
        litBrowser.Text +="Supports JavaScript = " + bc.JavaScript + "<br>";
        litBrowser.Text +="Supports Java Applets = " + bc.JavaApplets + "<br>";
        litBrowser.Text +="Supports ActiveX Controls = " + bc.ActiveXControls + "<br>";
        litBrowser.Text +="CDF = " + bc.CDF + "<br><br>";
        litBrowser.Text +="User-Agent = " + Request.UserAgent + "<br>";
    }

}

Before I fixed the problem, I was getting the following results:

Browser Capabilities:

Type = Mozilla
Name = Mozilla
Version = 0.0
Major Version = 0
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = False
Supports Tables = False
Supports Cookies = False
Supports VB Script = False
Supports JavaScript = False
Supports Java Applets = False
Supports ActiveX Controls = False
CDF = False

User-Agent = Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko

First, I figured I'd need to update the ie.browser file and drop it into the "App_Browsers" folder in the application. Below is what I modified it to.

ie.browser
<browsers>
    <browser id="IE" parentID="Mozilla">
        <identification>
            <userAgent match="MSIE (?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)" />
            <userAgent nonMatch="IEMobile" />
        </identification>

        <capture>
            <userAgent match="Trident/(?'layoutVersion'\d+)" />
        </capture>

        <capabilities>
            <capability name="browser"              value="IE" />
            <capability name="layoutEngine"         value="Trident" />
            <capability name="layoutEngineVersion"  value="${layoutVersion}" />
            <capability name="extra"                value="${extra}" />
            <capability name="isColor"              value="true" />
            <capability name="letters"              value="${letters}" />
            <capability name="majorversion"         value="${major}" />
            <capability name="minorversion"         value="${minor}" />
            <capability name="screenBitDepth"       value="8" />
            <capability name="type"                 value="IE${major}" />
            <capability name="version"              value="${version}" />
        </capabilities>
    </browser>

      <browser id="IE10Plus" parentID="Mozilla">
        <identification>
            <userAgent match="Trident\/7.0; rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)?)(?'letters'\w*))(?'extra'[^)]*)" />
            <userAgent nonMatch="IEMobile" />
        </identification>

        <capture>
            <userAgent match="Trident/(?'layoutVersion'\d+)" />
        </capture>

        <capabilities>
            <capability name="browser"              value="IE" />
            <capability name="layoutEngine"         value="Trident" />
            <capability name="layoutEngineVersion"  value="${layoutVersion}" />
            <capability name="extra"                value="${extra}" />
            <capability name="isColor"              value="true" />
            <capability name="letters"              value="${letters}" />
            <capability name="majorversion"         value="${major}" />
            <capability name="minorversion"         value="${minor}" />
            <capability name="screenBitDepth"       value="8" />
            <capability name="type"                 value="IE${major}" />
            <capability name="version"              value="${version}" />

            <capability name="ecmascriptversion"    value="3.0" />
            <capability name="jscriptversion"       value="5.6" />
            <capability name="javascript"           value="true" />
            <capability name="javascriptversion"    value="1.5" />
            <capability name="msdomversion"         value="${majorversion}.${minorversion}" />
            <capability name="w3cdomversion"        value="1.0" />
            <capability name="ExchangeOmaSupported" value="true" />
            <capability name="activexcontrols"      value="true" />
            <capability name="backgroundsounds"     value="true" />
            <capability name="cookies"              value="true" />
            <capability name="frames"               value="true" />
            <capability name="javaapplets"          value="true" />
            <capability name="supportsCallback"     value="true" />
            <capability name="supportsFileUpload"   value="true" />
            <capability name="supportsMultilineTextBoxDisplay" value="true" />
            <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
            <capability name="supportsVCard"        value="true" />
            <capability name="supportsXmlHttp"      value="true" />
            <capability name="tables"               value="true" />
            <capability name="supportsAccessKeyAttribute"    value="true" />
            <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter" />
            <capability name="vbscript"             value="true" />
        </capabilities>
    </browser>

    <!-- Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4325) -->
    <browser id="IE6to9" parentID="IE">
        <identification>
            <capability name="majorversion" match="[6-9]" />
        </identification>

        <capabilities>
            <capability name="ecmascriptversion"    value="3.0" />
            <capability name="jscriptversion"       value="5.6" />
            <capability name="javascript"           value="true" />
            <capability name="javascriptversion"    value="1.5" />
            <capability name="msdomversion"         value="${majorversion}.${minorversion}" />
            <capability name="w3cdomversion"        value="1.0" />
            <capability name="ExchangeOmaSupported" value="true" />
            <capability name="activexcontrols"      value="true" />
            <capability name="backgroundsounds"     value="true" />
            <capability name="cookies"              value="true" />
            <capability name="frames"               value="true" />
            <capability name="javaapplets"          value="true" />
            <capability name="supportsCallback"     value="true" />
            <capability name="supportsFileUpload"   value="true" />
            <capability name="supportsMultilineTextBoxDisplay" value="true" />
            <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
            <capability name="supportsVCard"        value="true" />
            <capability name="supportsXmlHttp"      value="true" />
            <capability name="tables"               value="true" />
            <capability name="supportsAccessKeyAttribute"    value="true" />
            <capability name="tagwriter"            value="System.Web.UI.HtmlTextWriter" />
            <capability name="vbscript"             value="true" />
        </capabilities>
    </browser>

    <!-- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;) -->
    <browser id="IE7" parentID="IE6to9">
        <identification>
            <capability name="majorversion" match="7" />
        </identification>
        <capabilities>
            <capability name="jscriptversion" value="5.7" />
        </capabilities>
    </browser>

    <!-- Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729) -->
    <browser id="IE8" parentID="IE6to9">
        <identification>
            <capability name="majorversion" match="8" />
        </identification>
        <capabilities>
            <capability name="jscriptversion" value="6.0" />
        </capabilities>
    </browser>


    <gateway id="IEbeta" parentID="IE">
        <identification>
            <capability name="letters" match="^([bB]|ab)" />
        </identification>

        <capture>
        </capture>

        <capabilities>
            <capability name="beta"    value="true" />
        </capabilities>
    </gateway>
</browsers>

My results from the browser page were unaffected, however - the browser was still being detected as "Mozilla". I decided to hack out the Mozilla detection from the generic.browser file (trying the "NonMatch" element didn't work for me - if someone can explain how to prevent IE11 detecting as Mozilla, I'd love to hear from you).

generic.browser
<browsers>
    <browser id="GenericDownlevel" parentID="Default">
        <identification>
            <userAgent match="^Generic Downlevel$" />
        </identification>

        <capture>
        </capture>

        <capabilities>
            <capability name="cookies"                     value="false" />
            <capability name="ecmascriptversion"           value="1.0" />
            <capability name="tables"                      value="true" />
        <capability name="type"                        value="Downlevel" />
        </capabilities>
        <controlAdapters>
        <adapter controlType="System.Web.UI.WebControls.Menu"
                     adapterType="System.Web.UI.WebControls.Adapters.MenuAdapter" />
        </controlAdapters>
    </browser>

</browsers>

After uploading the new browser files to the App_Browsers folder on the server I get the following and the website is working again! (Note: you may need to restart the application for this to take effect. If, like me, you don't have access to the server to do this, write a new file in the "bin" folder - any file changes in this folder cause an application to restart.)

Browser Capabilities:
Type = IE11
Name = IE
Version = 11.0
Major Version = 11
Minor Version = 0
Platform = WinNT
Is Beta = False
Is Crawler = False
Is AOL = False
Is Win16 = False
Is Win32 = True
Supports Frames = True
Supports Tables = True
Supports Cookies = True
Supports VB Script = True
Supports JavaScript = True
Supports Java Applets = True
Supports ActiveX Controls = True
CDF = False

User-Agent = Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko

Comments