移动设备上的 Response.Redirect 错误
在我的主登录屏幕上,我正在检查浏览器是否是移动浏览器。如果浏览器是移动浏览器,我会将用户重定向到移动网站登录屏幕。这在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查服务器上的事件查看器日志。可能还想尝试做 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.