Safari浏览器在iPad上偶尔会不承认ASP.NET回传链接 [英] Safari on iPad occasionally doesn't recognize ASP.NET postback links

查看:747
本文介绍了Safari浏览器在iPad上偶尔会不承认ASP.NET回传链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很艰难的时期查明间歇性问题的根源在第三代iPad运行iOS 6.0的Safari浏览器中运行ASP.NET Web应用程序。什么情况是,上一次,即< A> 设置为是通过JavaScript做回发会突然停止工作,并且不会出现,如果做任何事情的超级链接标签你触摸它们在屏幕上。这些措施包括 ASP:LinkBut​​ton的被设置为注销链路控制,以及一个GridView 的标题行设置为允许行排序。目前似乎没有无缘无故背后 - 他们将正常工作一段时间,然后停止了,我以后会发现,他们重新开始工作(关闭Safari浏览器,然后重新打开它,虽然总是不大多之后似乎工作)。

I'm having a really hard time pinpointing the source of an intermittent problem in an ASP.NET web application running on the Safari browser on a third-generation iPad running iOS 6.0. What happens is that, on occasion, the that <a> tags set up as hyperlinks that do postbacks via JavaScript will suddenly stop working and don't appear to do anything if you touch them on the screen. These include an asp:LinkButton control that is set up as a logout link, and the header row of a GridView that is set up to allowing row sorting. There seems to be no rhyme or reason behind it - they will work as normal for awhile, then stop, and I'll later notice that they start working again (mostly after closing Safari and re-opening it, though that doesn't always seem to work).

注销控制看起来像这样在aspx文件:

The logout control looks like this in the aspx file:

<asp:LinkButton ID="LogoutButton" onclick="LogoutButton_Click" runat="server">[ Logout ]</asp:LinkButton>

和,因为这会出现在生成的HTML:

and appears as this in the resulting HTML:

<a id="LogoutButton" href="javascript:__doPostBack(&#39;ctl00$LogoutButton&#39;,&#39;&#39;)">[ Logout ]</a>

有什么特别之处对iPad可能prevent等环节突破之际,运行Safari浏览器,如加载的页面或其他打开的浏览器标签页过多的数据,或或许真的与在这种情况下犯了ViewState的?即使在iPad上的Web应用程序一段时间玩耍后,我找不到重现问题的任何特定的方式,所以我不能甚至开始尝试修复它这是很无奈,所以我在寻找从这些谁开发ASP.NET应用程序,并知道iPad和/或Safari环境真的很好的指导。我从来没有过这种问题发生在桌面浏览器。

Is there anything special about Safari running on the iPad that might prevent such links to break on occasion, such as too much data loaded on the page or in other open browser tabs, or maybe something with the ViewState that is acting up in this scenario? Even after playing around with the web application on the iPad for awhile, I can't find any particular way to recreate the problem, so I can't even begin to try to fix it which is really frustrating, so I'm looking for guidance from those who have developed ASP.NET apps and know the iPad and/or Safari environments really well. I've never had this problem occur on a desktop browser.

更新:使用概述的的此页面如何伪查看源选项添加到Safari浏览器在iPad上,我现在已经能够看到在回传链路工作页面生成的HTML的差异,以及它的停止页面。总之,在 __ doPostBack JavaScript函数ASP.NET通常体内埋下的网页...只是停止得到嵌入出于某种原因。其结果是,JavaScript的绑在链路简单地错误输出。下面是ASP.NET通常添加到页面以获取回传链路工作:

Update: Using the trick outlined on this page about how to add a pseudo-View Source option to Safari on the iPad, I have now been able to see the difference in the generated HTML of a page where the postback links are working, and a page where it's stopped. In short, the __doPostBack JavaScript function that ASP.NET normally imbeds in the page... simply stops getting imbedded for some reason. As a result, the JavaScript tied to the links simply error out. Here's what ASP.NET normally adds to the page to get the postback links working:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

这似乎是在苹果支持论坛中描述了同样的问题和<一个href=\"http://stackoverflow.com/questions/917688/asp-net-not-generating-javascript-for-some-user-agents\">here在SO 。后者认为,ASP.NET有时可能没有认识到iPad上的Safari浏览器为能够JavaScript的,因此不正确插入的 __ doPostBack 函数到页面中。我的网页上其他JavaScript仍然工作正常,虽然,所以它并不能完全解释我的问题。

This appears to be the same issue described on the Apple support forum and here on SO. The latter suggests that ASP.NET may sometimes be failing to recognize Safari on the iPad as being JavaScript capable and thus doesn't properly insert the __doPostBack function into the page. Other JavaScript on my page is still working fine, though, so it doesn't fully explain my problem.

推荐答案

找到后<一个href=\"http://stackoverflow.com/questions/10511145/asp-net-ajax-postback-suddenly-stops-on-iphone-ipad\">this对堆栈溢出问题几乎同样的问题,我跑了的browserCaps输出页面斯蒂芬建议,发现Safari浏览器,当从iPad的主屏幕上的链接全屏模式下运行,似乎我们的ASP.NET服务器作为一种通用的,无能力的浏览器。我应用了,其他问题由阿瓦达索命提​​出的修正,从而享有把这个:

After finding this question on Stack Overflow with virtually the same problem, I ran the browserCaps output page suggested by Stephen and found that Safari, when run in full screen mode from a link on the iPad's home screen, appeared to our ASP.NET server as a generic, no capability browser. I applied the fix suggested by Avada Kedavra in that other question, which entailed putting this:

<browserCaps userAgentCacheKeyLength="256" />

......到&LT;&的System.Web GT; 我的web.config文件的部分,也是这个:

...into the <system.web> section of my web.config file, and also this:

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

在隐藏文件的主网页行事了code。 杰森Kealey 的,其他人的修复程序的源代码,也在他的研究结果的评论部分表明,它也可能是有益的这种添加到您的ASP.NET Web应用程序的文件夹App_Browsers文件一个.browser文件:

in the code behind file for the main web page that was acting up. Jason Kealey, the source of that other person's fix, also suggests in the comments section of his findings that it might also be helpful to add this to a .browser file in the App_Browsers folder of your ASP.NET web application:

<browsers>
  <browser refID="Mozilla" >
    <capabilities>
      <capability name="cookies"  value="true" />
      <capability name="type" value="Uplevel" />
    </capabilities>
  </browser>

  <browser refID="Default">
    <capabilities>
      <capability name="cookies" value="true" />
      <capability name="type" value="Uplevel" />
    </capabilities>
  </browser>
</browsers>

编辑:
我应用此修复程序到我的应用程序,但它打破了其他领域,具体而言,它是识别Chrome和Safari为uplevel,这导致它在其他领域的IE进行检测。在code以下,使此修复程序只适用于当的iDevices在用户代理如Safari没有确定:

I applied this fix to my application, but it broke other areas, specifically, it was identifying Chrome and Safari as "uplevel", which caused it to be detected in other areas as "IE". The code below makes this fix only apply to iDevices when not identified in the user agent as Safari:

string ua = Request.UserAgent;
if (ua != null
    && (ua.IndexOf("iPhone", StringComparison.CurrentCultureIgnoreCase) >= 0
    || ua.IndexOf("iPad", StringComparison.CurrentCultureIgnoreCase) >= 0
    || ua.IndexOf("iPod", StringComparison.CurrentCultureIgnoreCase) >= 0)
    && ua.IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) < 0)
{
    this.ClientTarget = "uplevel";
}

这篇关于Safari浏览器在iPad上偶尔会不承认ASP.NET回传链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆