Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net 4.0, JavaScript Not Outputted in IE 11

In our ASP.Net 4.0 project, we're noticing that in IE 11 only (both on Windows 7 SP1 and Windows 8.1), some JavaScript is not being outputted by ASP.Net.

For e.g. in IE 10 and below, we see this:

<select name="ctl00$ctl00$cpHeading$cpHeading$ucWebStoreHeader$lshSubjectHeader$ddlVersionList" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$ctl00$cpHeading$cpHeading$ucWebStoreHeader$lshSubjectHeader$ddlVersionList\&#39;,\&#39;\&#39;)&#39;, 0)" id="ctl00_ctl00_cpHeading_cpHeading_ucWebStoreHeader_lshSubjectHeader_ddlVersionList">

While in IE 11:

<select name="ctl00$ctl00$cpHeading$cpHeading$ucWebStoreHeader$lshSubjectHeader$ddlVersionList" id="ctl00_ctl00_cpHeading_cpHeading_ucWebStoreHeader_lshSubjectHeader_ddlVersionList">

We're setting this script using:

Page.ClientScript.RegisterClientScriptBlock(GetType(), null, script, true);

Could this be because .Net 4.0 does not have updated browser definition files to recognize IE 11 with its non-"MSIE" user agent string?

I went with that assumption and have tried Scott Hanselman's suggestion of installing KB2836939 on both a Win 7 SP1 and a Win Server 2008 R2 on the machine that hosts the web app, but I don't notice updates to any .browser files in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers or C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\Browsers.

So, I ended up creating my own .browser file, placed it in the folders above and AppBrowsers without luck (ran aspnet_regbrowsers –i and iisreset). Here’s the content of the IE11.browser file I placed in the folders:

<browsers>
<browser id="IE11" parentID="Mozilla">
<identification>
    <userAgent match="Trident/(?'layoutVersion'[7-9]|0*[1-9]\d+)(\.\d+)?;(.*;)?\s*rv:(?'version'(?'major'\d+)(\.(?'minor'\d+)))" />
    <userAgent nonMatch="IEMobile" />
    <userAgent nonMatch="MSIE" />
</identification>    
<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="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="6.0" />
    <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>
</browsers>

Am I on the right track thinking that the missing JavaScript is because of IE 11 not being recognized by .Net 4.0? If yes, why is my .browser not taking effect?

Everyone's time and help is much appreciated.

like image 613
Karthik Avatar asked Sep 30 '13 14:09

Karthik


2 Answers

Installing .Net 4.5 on the web server resolved the issue (without web app needing to use 4.5). Here's why I believe 4.5 did the trick.

IE 11 has a user agent (UA) string that does not contain "MSIE" unlike all previous versions of IE. IE 11 has UA string:

Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko

IE 10 (and below) have UA strings like:

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)

The browser definition shipped to recognize various versions of IE (ie.browser under c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers), looks specifically for "MSIE" in the UA string, adding JavaScript capability based on IE version matched. With IE 11, a match is not found in ie.browser, instead a match is found in generic.browser (). In .Net 4.0, generic.browser disables JavaScript, while in 4.5, it is enabled, resolving our issue.

I don't know why manually editing any of the .browser files and then running aspnet_regbrowsers –i and iisreset doesn't accomplish the same.

like image 87
Karthik Avatar answered Nov 10 '22 07:11

Karthik


@Adhooo is correct in saying that .Net 4.5 is not available to Windows 2003 Servers, so if you're running a Windows 2003 Server to host your website, changing to 2008 Server isn't an overnight option.

To be honest, for us, upgrading to .Net 4.5 on our 2008 Server isn't an overnight option, nor in-fact is it something we can do for the next several months, due to needing various testing done before being able to use 4.5 on our Production servers.

But we still needed to fix this problem for our visitors to our website.

Here's what we found we needed to do to remedy the problem and buy us some time before we can ultimately fix the problem by following Microsoft's advice of getting 4.5 out there:

  1. Browser File - we, too, modified the browser file to instruct the .Net Framework on how to respond to the use of IE11.
  2. Microsoft Patch - we then installed the patch (http://support.microsoft.com/kb/2836939/en-us) and rebooted.
  3. Register the new browser modifications - from a command line, running the following line:

    c:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regbrowsers.exe -i

  4. Reset IIS - this needed doing to ensure that IIS then picked up the changes to the files:

    iisreset

We were then in a position whereby our website was useable in IE11 and following much needed QA Testing, we were then able to have our visitors use the website, in a Production environment.

But please note, that if you play around with the process and need to re-apply the browser files to the server, then you have to use the 'aspnet_regbrowsers.exe –u' uninstall flag to un-register the files before you re-apply them. Also, in our case, we also needed to reapply the MS patch, as nothing worked again properly until we did.

Yes, all a bit messy - but this should be seen as an in-fill process.

Hope this helps.

like image 21
Brett Rigby Avatar answered Nov 10 '22 09:11

Brett Rigby