ASP.NET MVC 4中的移动显示模式在运行约一小时后停止提供正确的视图,尽管浏览器覆盖正确地检测到了被覆盖的移动设备。
重新启动应用程序池可以暂时解决该问题。
新的浏览器覆盖功能允许移动设备正确查看站点的桌面版本,反之亦然。但是约经过一小时的运行时间后,移动视图不再呈现给移动设备;仅呈现默认的桌面 Razor 模板。唯一的解决方法是重新启动应用程序池。
奇怪的是,浏览器覆盖 cookie 仍然起作用。一个主要的_Layout.cshtml
模板正确显示“mobile”或“desktop”文本,具体取决于 ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice
值,但仍会呈现错误的视图。这使我相信问题出在 DisplayModes 上。
所涉及的操作没有被缓存:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
我正在使用51Degrees进行移动设备检测,但我认为这不应影响覆盖的移动设备检测。ASP.NET MVC 4 Beta和Developer Preview中的DisplayModes
功能是否存在错误,还是我做错了其他事情?
以下是我在
Application_Start
中设置的DisplayModes
:DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
{
ContextCondition = context =>
context.GetOverriddenBrowser().IsMobileDevice
&& (context.Request.UserAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) >= 0
|| context.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0
|| !context.Request.Browser.IsMobileDevice)
});
/* Looks complicated, but renders Home.iPhone.cshtml if the overriding browser is
mobile or if the "real" browser is on an iPhone or Android. This falls through
to the next instance Home.Mobile.cshtml for more basic phones like BlackBerry.
*/
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("Mobile")
{
ContextCondition = context =>
context.GetOverriddenBrowser().IsMobileDevice
});