如何MVC4检测移动浏览器? [英] How does MVC4 detect a mobile browser?
问题描述
我只是跟着上<斯科特Hanselmans教程href=\"http://www.hanselman.com/blog/MakingASwitchableDesktopAndMobileSiteWithASPNETMVC4AndJQueryMobile.aspx\">making可切换的网站MVC4。
我使用的Opera Mobile模拟器测试,因为我没有VS2102。
I'm using the Opera mobile emulator to test as I don't have VS2102.
渲染模拟器我的网页当 Request.Browser.IsMobileDevice
是假的,虽然它仍然呈现移动视图。
When rendering my page in the emulator Request.Browser.IsMobileDevice
is false although it still renders the mobile view.
我的问题是:
- 为什么/如何MVC4决定使移动的看法?它似乎并不像它看起来在
Request.Browser.IsMobileDevice
。 - 将视图切换显示一个真正的移动设备上?
编辑:
我想我意识到自己的错误:
I think I realised my mistake:
要得到它与Opera模拟器我加工作 MobileDisplayMode
如下所述:
ASP.NET MVC 4移动功能
To get it to work with the opera emulator I added a MobileDisplayMode
as described here:
ASP.NET MVC 4 Mobile Features
看来,该解决方案可与渲染正确,但是 Request.Browser.IsMobileDevice
将不起作用。这同样适用于 ViewContext.HttpContext.GetOverriddenBrowser()。IsMobileDevice
有没有办法来解决这个问题?
It seems that that solution works with rendering correctly but Request.Browser.IsMobileDevice
won't work. The same goes for ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice
is there a way to get around this?
推荐答案
MVC识别移动设备通过下与浏览器配置文件present HTTP请求头相匹配:\\ WINDOWS \\ Microsoft.NET \\ Framework64 \\ v4.0.30319 \\ CONFIG \\浏览器
MVC recognize Mobile device by matching the HTTP request header with browser config files present in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers
在asp.net MVC的浏览器检测方法也不是很大,所以我建议使用某种DDR的
The asp.net MVC browser detection approach is not great so i recommend using some sort of DDR
这篇关于如何MVC4检测移动浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!