WURFL的手机 [英] WURFL for Mobiles

查看:103
本文介绍了WURFL的手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC Global.asax中的Application_Start事件中使用下面code。 WURFL检测手机的。低于code作品表和iPad的限制,但不能用于三星Galaxy Tab在10英寸以上。

  DisplayModeProvider.Instance.Modes.Insert(0,新DefaultDisplayMode()
     {
     ContextCondition =(上下文=> context.GetOverriddenUserAgent()的IndexOf(平板,StringComparison.OrdinalIgnoreCase)方式> = 0
 || 。context.GetOverriddenUserAgent()的IndexOf(iPad是,StringComparison.OrdinalIgnoreCase)GT; = 0)
     });


解决方案

如果您希望通过

检查您可以查询WURFL所有药片

 公共类全球:一个HttpApplication
{
    公共常量字符串WurflDataFilePath =〜/ App_Data文件/ wurfl.zip
    私人无效的Application_Start(对象发件人,EventArgs的发送)
    {
        VAR wurflDataFile = HttpContext.Current.Server.MapPath(WurflDataFilePath);
        VAR wurflPatchFile = HttpContext.Current.Server.MapPath(WurflPatchFilePath);
        无功配置器=新InMemoryConfigurer()
                 .MainFile(wurflDataFile)
        VAR经理= WURFLManagerBuilder.Build(配置器);
        HttpContext.Current.Cache [WurflManagerCacheKey] =经理;
    }
}无功装置= WURFLManagerBuilder.Instance.GetDeviceForRequest(的userAgent);
变种IS_TABLET = device.GetCapability(IS_TABLET);如果(IS_TABLET ==真){
    //显示平板电脑版网站
}其他{
    //显示桌面网站
}

I am using below code in Application_Start event of Global.asax in ASP.NET MVC. WURFL for detection of Mobiles. Below code works for restriction of tables and ipads but not for Samsung Galaxy Tab greater than 10 inches.

     DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode()
     {
     ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf("tablet",  StringComparison.OrdinalIgnoreCase) >= 0
 || context.GetOverriddenUserAgent().IndexOf("ipad", StringComparison.OrdinalIgnoreCase) >= 0)
     });

解决方案

If you would like to check for all tablets you can query WURFL by

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
}

这篇关于WURFL的手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆