ASP.NET Ajax 回发在 iPhone/iPad 上突然停止

标签 asp.net iis postback mobile-safari

我有一个 Asp.Net 4.0 网站/控制界面,它使用更新面板和一些按钮。更新面板连接到每 5 秒执行一次的计时器,从而导致部分回发。这些按钮会切换一些设置,然后通过类似于以下的调用强制更新更新面板:

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('<%= UpdatePanel.ClientID %>', '');
return true;

该网站在 IE/Firefox 和 Safari 移动设备 (IPhone/iPad) 上运行良好,但在移动设备上回发会随机且静默地停止工作。我认为这可能与节省电池有关,并且 safari 在空闲时关闭部分回发。问题是,当用户返回站点时,回发完全关闭,计时器和按钮都不再导致任何回发。 (我已经监控服务器上的网络流量来验证这一点)。即使用户刷新网站(多次),部分回发也不会重新发挥作用。它只是停止向服务器发送数据。然后突然并且没有特殊原因,回发再次开始工作。停机时间通常长达 10 分钟,这使得我的网站完全无法实现其目的。

考虑到回发再次开始需要很长时间,我想知道客户端或 IIS 中是否有任何设置可以使用?

该网站将仅在我的客户设备上运行,它不是公开的,因此,如果客户端上有任何设置可供使用,我愿意这样做。

我对此感到非常困惑,并且还没有找到触发“错误”的方法,它只是有时会发生。非常感谢任何建议和提示。

<小时/>

更新:

添加了一些错误处理,当回发失败时,我(不一致)收到以下消息:

The page is performing an async postback but the ScriptManager.SupportParialRendering property is set to false. Ensure that the property is set to true during postback.

奇怪的是,这个属性在第一个实例中显然对于设备来说是正确的,否则回发将永远不会工作,但事实并非如此。

<小时/>

更新2: 发现以下博客文章建议更改 web.config 中的 browserCap 设置。现在正在尝试这个。会回来报告。其他建议仍然很受欢迎。 ASP.NET 4 BrowserCaps (or: what were they thinking?)

以上内容在全屏模式下禁用 safari mobile 中的 javascript(从主屏幕运行)。以下文章建议解决此问题。 Gotcha: iPad versus ASP.NET

最佳答案

我的问题中“更新 2”下的发现解决了该问题。显然,Safari UserAgents 有时会识别为 Mozilla 0.0,如以下博客文章所示: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. ...

页面下方:

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.

所以,输入 <browserCaps userAgentCacheKeyLength="256" /> Web.Config 中解决了该问题。

<小时/>

不幸的是,当 safari 浏览器在全屏模式下使用时(链接保存在主屏幕上),这会导致另一个问题。在全屏模式下,Safari 使用不同的 HTTP 用户代理字符串,ASP.NET 不再将浏览器识别为 Safari,而是将其识别为没有任何功能的通用浏览器,例如 JavaScript 和 JQuery 将停止工作。 Gotcha: iPad versus ASP.NET 中对此进行了进一步阐述。 。解决方案是在每个网站的 Page_Init 中添加以下内容。不是很优雅,但它可以与上面的一起使用:

protected void Page_PreInit(object sender, EventArgs e)
{
   if (Request.UserAgent != null && Request.UserAgent.IndexOf("AppleWebKit", StringComparison.CurrentCultureIgnoreCase) > -1)
   {
      this.ClientTarget = "uplevel";
   }
}

关于ASP.NET Ajax 回发在 iPhone/iPad 上突然停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10511145/

相关文章:

asp.net - 使用主页侧栏滚动 iframe

asp.net - 在 UpdatePanel 中使用 GridView 时数据不同步

asp.net - 物理文件夹破坏了 IIS Express 上的 ASP.NET URL 路由

Python导入错误 "DLL load failed"| Python

c# - 在 ASMX Web 服务中使用 Server.Execute() 呈现 UserControl 的问题

c# - 在按钮单击事件中显示在 ASP 日历中选择的日期

angular - 在 IIS 默认网站下托管 .Net Core 应用和 Angular 应用

java - 来自 java 的 asp.NET 帖子

postback - 向 Paypal 发送保存按钮 ipn 问题上的 "custom"变量

asp.net - 如何使用javascript生成假回发?