尽管浏览器覆盖正确检测到被覆盖的移动设备,但ASP.NET MVC 4中的移动显示模式在大约一小时的正常运行时间后停止提供正确的视图.
回收应用程序池暂时解决了这个问题.
新的浏览器覆盖功能正确地允许移动设备查看站点的桌面版本,反之亦然.但经过大约一个小时的正常运行时间后,移动设备不再呈现移动视图; 仅呈现默认桌面Razor模板.唯一的解决方法是回收应用程序池.
奇怪的是,浏览器覆盖cookie继续运行.主_Layout.cshtml模板正确显示"移动"或"桌面"文本,具体取决于值ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice,但仍会呈现错误的视图.这让我相信问题在于DisplayModes.
有问题的行动没有被缓存:
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
Run Code Online (Sandbox Code Playgroud)
我使用51Degrees进行移动检测,但我不认为这会影响被覆盖的移动检测.这是DisplayModesASP.NET MVC 4 Beta和开发人员预览的功能中的错误,还是我做错了什么?
这是我的DisplayModes设置Application_Start:
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 …Run Code Online (Sandbox Code Playgroud)