加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET Ajax回发突然停止在IPhone / IPad上

发布时间:2020-12-16 04:05:29 所属栏目:asp.Net 来源:网络整理
导读:我有一个Asp.Net 4.0网站/控制界面,它使用更新面板和一些按钮.更新面板连接到每5秒执行一次的计时器,导致部分回发.按钮切换一些设置,然后通过类似于此的调用强制更新更新面板: var prm = Sys.WebForms.PageRequestManager.getInstance();prm._doPostBack('%
我有一个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中是否有任何设置可以使用?

该网站将仅在我的客户设备上运行,而不是公开的,所以如果在客户端上有任何设置可以使用,我就是为了它.

我对此感到很困惑,并没有找到触发“bug”的方法,有时会发生这种情况.任何建议和提示都非常感谢.

更新:

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

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";
   }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读