移动设备上的 Response.Redirect 错误

发布于 2024-12-10 03:41:43 字数 1402 浏览 0 评论 0原文

在我的主登录屏幕上,我正在检查浏览器是否是移动浏览器。如果浏览器是移动浏览器,我会将用户重定向到移动网站登录屏幕。这在我的 Android 设备上运行良好,但在我的 iPhone 上则不然。我尝试在重定向后放入 Response.End(),但这导致我的 Android 设备开始收到错误消息。我在两台设备上收到的消息是有很多服务器重定向。有什么提示吗?

编辑:

if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" 
            || Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC") 
            || Request.UserAgent.ToLower().Contains("iphone") || Request.UserAgent.ToLower().Contains("avant") 
            || Request.UserAgent.ToLower().Contains("nokia") || Request.UserAgent.ToLower().Contains("pda") 
            || Request.UserAgent.ToLower().Contains("moto") || Request.UserAgent.ToLower().Contains("windows ce") 
            || Request.UserAgent.ToLower().Contains("hand") || Request.UserAgent.ToLower().Contains("mobi") 
            || Request.UserAgent.ToUpper().Contains("HTC") || Request.UserAgent.ToLower().Contains("sony") 
            || Request.UserAgent.ToLower().Contains("panasonic") || Request.UserAgent.ToLower().Contains("blackberry") 
            || Request.UserAgent.ToLower().Contains("240x320") || Request.UserAgent.ToLower().Contains("voda"))
            || Request.UserAgent.ToLower().Contains("android") || Request.UserAgent.ToLower().Contains("ipad")) 
        {
            Response.Redirect("~/Mobile/Login.aspx");
        }

On my main login screen, i am checking to see if the browser is a mobile browser. If the browser is a mobile browser i redirect the user to the mobile website login screen. This works fine on my Android device but not on my Iphone. I went and tried putting in Response.End() after my redirects but that caused my Android device to start getting the error message. The message i am getting on both devices is that there are to many server redirects. Any Hints?

Edit:

if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" 
            || Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC") 
            || Request.UserAgent.ToLower().Contains("iphone") || Request.UserAgent.ToLower().Contains("avant") 
            || Request.UserAgent.ToLower().Contains("nokia") || Request.UserAgent.ToLower().Contains("pda") 
            || Request.UserAgent.ToLower().Contains("moto") || Request.UserAgent.ToLower().Contains("windows ce") 
            || Request.UserAgent.ToLower().Contains("hand") || Request.UserAgent.ToLower().Contains("mobi") 
            || Request.UserAgent.ToUpper().Contains("HTC") || Request.UserAgent.ToLower().Contains("sony") 
            || Request.UserAgent.ToLower().Contains("panasonic") || Request.UserAgent.ToLower().Contains("blackberry") 
            || Request.UserAgent.ToLower().Contains("240x320") || Request.UserAgent.ToLower().Contains("voda"))
            || Request.UserAgent.ToLower().Contains("android") || Request.UserAgent.ToLower().Contains("ipad")) 
        {
            Response.Redirect("~/Mobile/Login.aspx");
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2024-12-17 03:41:43

检查服务器上的事件查看器日志。可能还想尝试做 Response.Redirect(urlString, false);

响应.重定向(urlString);在内部执行 Response.End() 并可能导致线程中止问题。这是预料之中的,没什么大不了的,但它会抛出异常。

Check event viewer logs on the server. Might also want to try doing Response.Redirect(urlString, false);

Response.Redirect(urlString); does a Response.End() inside and can cause issues with threads aborting. This is expected and not a big deal but it will throw as an exception.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文