# Thursday, 05 December 2013

When Internet Explorer 10 launched, it caused some problems with the antiquated browser detection feature of ASP.Net, and thus you needed to make sure that you installed the right patches or performed the right fixes in order to get everything working properly. And I talk about the IE10 incident here on my blog.

And now Internet Explorer 11 has just been auto updated to many users, and again I was seeing problems with my websites. At a MUCH worse scale this time I might add, not only were scripts not being sent ASP.Net didn't think IE11 was capable of receiving cookies which just royally broke the website.

Sometimes your site might seem ok, but buttons are not working and everything that seems to be tied to Javascript seems to be malfunctioning, looking into the Javascript debug console you see something similar to this message :-

'__doPostBack' is undefined

or something like

'WebForm_DoPostBackWithOptions' is undefined.

Once again Scott Hanselman talks about the problem, and mentions the obvious solution of ensuring your server patches were up to date.

But I couldn't get my client's servers patched for some reason, so I hunkered down and tried to manually patch the browser definition file. At first I thought I could just insert the new version into the existing IE browser definition file like it was done for IE10 the last time. Then I actually saw the IE11 user agent string:-

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

The MSIE moniker which was used to identify Internet Explorer was DELIBRATELY removed, because IE11 is more than capable of handling HTML5 now and they didn't want any poorly coded Javascript library to incorrect identify IE11 as being an older, less HTML5 capable browser and tell users to use some other browser instead. Very good intentions I must say, too bad ASP.Net brefore 4.5 happens to be one of those legacy systems that do User Agent sniffing and because it didn't see anything it knew was defaulting IE11 to something which couldn't handle Javascript, Cookies, and many many other things.

At first I thought about writing a regular expression pattern which could parse the new User Agent and identify the browser properly. But there were 2 problems with that idea. The first was that I was CRAP at writing complex regular expressions, the second was the fact that why should I even bother with browser sniffing? Every damn browser supports Javascript now, and websites pretty much NEED Javascript anyway. So I set about to make it so that the default browser definition enabled all modern features.

I did so by overriding the default browser defintion at my web site level. First I created a app_browsers folder in the root of the web site, then I create a file called newdef.browser with the following content

UPDATE Jan 30th 2013 : You might not see changes right away when you drop the file in, you might want to try restarting the IIS web pool, if you can't do that, try toggling the compilation/debug attribute under system.web in the root web.config file by alternating it between true and false to restart it.

<?xml version="1.0" encoding="utf-8"?>
<browsers>
<browser refID="Default">
 <capabilities>
  <capability name="browser" value="Generic UpLevel" />         
            <capability name="type"                            value="Generic" />
            <capability name="ecmascriptversion"               value="3.0" />
            <capability name="javascript"                      value="true" />
            <capability name="javascriptversion"               value="1.7" />
            <capability name="w3cdomversion"                   value="1.0" />
            <capability name="supportsAccesskeyAttribute"      value="true" />
            <capability name="tagwriter"                       value="System.Web.UI.HtmlTextWriter" />
            <capability name="cookies"                         value="true" />
            <capability name="frames"                          value="true" />
            <capability name="javaapplets"                     value="true" />
            <capability name="supportsCallback"                value="true" />
            <capability name="supportsDivNoWrap"               value="false" />
            <capability name="supportsFileUpload"              value="true" />
            <capability name="supportsMaintainScrollPositionOnPostback" value="true" />
            <capability name="supportsMultilineTextBoxDisplay" value="true" />
            <capability name="supportsXmlHttp"                 value="true" />
            <capability name="tables"                          value="true" />
        </capabilities>
</browser>
</browsers>

What the file does is that it overrides the default browser definition of a crummy featureless browser to a more up to date one which supports all the cool stuff like cookies, Javascript, etc. etc. I basically just copied all the capability tags from the Chome browser definition file.

WARNING : If for some poor unfortunate reason that you actually RELY on ASP.Net's browser detection feature to detect ancient browsers this will effectively BREAK the function so do so at your own risk!


Note that you can Post As GUEST as well.
blog comments powered by Disqus
Thursday, 05 December 2013 23:29:33 (Malay Peninsula Standard Time, UTC+08:00)  #    Comments [0]  |