我在ASP.NET MVC的Global.asax的Application_Start事件中使用了下面的代码。用于手机检测的WURFL。下面的代码适用于桌面和ipads的限制,但不适用于大于10英寸的三星Galaxy Tab。
DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode()
{
ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("tablet", StringComparison.OrdinalIgnoreCase) >= 0
|| context.GetOverriddenUserAgent().IndexOf("ipad", StringComparison.OrdinalIgnoreCase) >= 0)
});发布于 2014-11-14 10:53:11
如果您想查看所有平板电脑,可以通过以下方式查询WURFL
public class Global : HttpApplication
{
public const String WurflDataFilePath = "~/App_Data/wurfl.zip";
private void Application_Start(Object sender, EventArgs e)
{
var wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
var wurflPatchFile = HttpContext.Current.Server.MapPath(WurflPatchFilePath);
var configurer = new InMemoryConfigurer()
.MainFile(wurflDataFile)
var manager = WURFLManagerBuilder.Build(configurer);
HttpContext.Current.Cache[WurflManagerCacheKey] = manager;
}
}
var device = WURFLManagerBuilder.Instance.GetDeviceForRequest(userAgent);
var is_tablet = device.GetCapability("is_tablet");
if (is_tablet == true) {
// Show tablet site
} else {
// Show desktop site
}https://stackoverflow.com/questions/26859187
复制相似问题