如何检测请求是否来自我的 asp.net MVC 3 中的移动浏览器 [英] How can i detect if the request is coming from a mobile browser in my asp.net MVC 3
问题描述
我想要实现的目标很简单;在我的 Web 应用程序中的所有视图中,我只有两个 razor 视图,我为它们创建了移动版本.因此,如果用户从移动设备访问应用程序,我需要将用户重定向到这些视图.我在控制器级别尝试了以下操作,但是当我在不同的移动设备上运行测试时它没有重定向用户:-
what i am trying to achieve is simple; Among all the view which i have in my web application, i have only two razor views that i have created a mobile version for them. so i need to redirect the users to these views if they are accessing the application from their mobile devices. i tried the following on the controller level but it did not redirect the users when i run my test on different mobile devices :-
if (Request.Browser.IsMobileDevice)
{
return View("MobileStudentStartAssessment");
}
else {
return View("StudentStartAssessment");
}
那么我可以遵循另一种方法来检测大多数移动设备吗?谢谢
So is there another approach that i can follow which can detect most of the mobile devices? Thanks
推荐答案
您可以使用 Request.Browser.IsMobileDevice
属性.
You can use the Request.Browser.IsMobileDevice
property.
这篇关于如何检测请求是否来自我的 asp.net MVC 3 中的移动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!