ASP.NET Webforms Doesn't Render Postback JavaS

2020-02-26 00:50发布

问题:

When we supply the user agent Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X; en-us) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/21.0.1180.80 Mobile/9A405 Safari/7534.48.3 to our .NET 4 webforms app, the script that defines the function __doPostBack is not present on the page and thus nothing that uses it works.

If we supply any other user agent string (say, Safari) it works fine. Can someone explain this?

回答1:

So the problem is that the Chrome user agent isn't recognized by .net and so it assumes that it's dealing with a low-level browser.

To solve, we added ~/App_Browsers/CriOS.browser with the following contents:

<browsers>
    <browser id="CriOS" parentID="Safari">
        <identification>
            <userAgent match="CriOS" />
        </identification>

        <capabilities>
            <capability name="browser" value="CriOS" />
            <capability name="ecmascriptversion" value="3.0" />
            <capability name="javascript" value="true" />
            <capability name="javascriptversion" value="1.7" />
        </capabilities>
    </browser>
</browsers>