我正在尝试为平板电脑和移动设备制作单独的视图.在app_start我有这个代码
DisplayModeProvider.Instance.Modes.Insert(0, new
DefaultDisplayMode("Tablet")
{
ContextCondition = (ctx =>
ctx.Request.UserAgent.IndexOf("iPad", StringComparison.OrdinalIgnoreCase) >= 0 ||
ctx.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0)
});
Run Code Online (Sandbox Code Playgroud)
我创建了两个布局文件,一个用于移动设备,另一个用于平板电脑.但是当我从Android上的移动设备访问时存在冲突.它将我重定向到layout.tablet.我怎么能分开这两个设备?
我在浏览器中使用用户代理切换器对此进行了测试,它运行正常.
DisplayModeProvider.Instance.Modes.Insert(0, new
DefaultDisplayMode("Tablet")
{
ContextCondition = (ctx =>
ctx.Request.UserAgent.IndexOf("iPad", StringComparison.OrdinalIgnoreCase) >= 0 ||
ctx.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0 &&
ctx.Request.UserAgent.IndexOf("mobile", StringComparison.OrdinalIgnoreCase) < 1)
});
DisplayModeProvider.Instance.Modes.Insert(1, new DefaultDisplayMode("Mobile")
{
ContextCondition = (ctx =>
ctx.GetOverriddenBrowser().IsMobileDevice)
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4352 次 |
| 最近记录: |