WURFL for Mobiles

时间:2014-11-11 06:49:20

标签: asp.net

我在ASP.NET MVC中的Global.asax的Application_Start事件中使用下面的代码。用于检测手机的WURFL。下面的代码适用于限制表和ipads,但不适用于大于10英寸的Samsung 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)
     });

1 个答案:

答案 0 :(得分:0)

如果您想查看所有平板电脑,可以通过

查询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
}