ASP.NET Ajax postback suddenly stops on IPhone/IPad

橙三吉。 提交于 2019-11-30 19:41:54

The findings under "update 2" in my question solves the issue. Apparently the Safari UserAgents occasionally recognized as Mozilla 0.0, as identified in the following blog post: ASP.NET 4 BrowserCaps (or: what were they thinking?):

The first WTF is that the .NET framework actually throws an exception if it detects an async postback from a browser that according to BrowserCaps does not support async postback. It’s as if they think they know best who is capable of async postbacks even with overwhelming evidence to the contrary…

The next WTF was substantially harder to find. Why are Safari UserAgents occasionally recognized as Mozilla 0.0 and why was I never able to reproduce the issue even when using a UserAgent string that I just copied from an exception?

The answer lies in

<browserCaps userAgentCacheKeyLength="64" />

The default setting for the user agent cache key length is to take the first 64 characters of the UserAgent string. ...

And further down the page:

Setting the userAgentCacheKeyLength to 256 solved the problem, even though there are still UserAgent strings out there that are identified as Mozilla 0.0. At least now it’s consistent.

So, putting <browserCaps userAgentCacheKeyLength="256" /> in Web.Config solves the issue.


This unfortunately causes another problem when the safari browser is used in fullscreen mode (link saved on the home screen). In fullscreen mode Safari uses a different HTTP User Agent String, and ASP.NET doesn't anymore recognize the browser as Safari, instead it recognizes it as a generic browser with no capabilities and for example JavaScript and JQuery will stop working. The is further elaborated in Gotcha: iPad versus ASP.NET. The solution is to put the following in Page_Init on each website. Not very elegant, but it works together with the above:

protected void Page_PreInit(object sender, EventArgs e)
{
   if (Request.UserAgent != null && Request.UserAgent.IndexOf("AppleWebKit", StringComparison.CurrentCultureIgnoreCase) > -1)
   {
      this.ClientTarget = "uplevel";
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!