IsMobileDevice 如何工作? [英] How does IsMobileDevice work?

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

问题描述

MSDN 让检测移动浏览器听起来如此简单:

MSDN makes it sound so easy to detect a mobile browser:

if (Request.Browser["IsMobileDevice"] == "true" ) 
{
    Response.Redirect("MobileDefault.aspx");
}

实际上,您似乎也可以只检查 Request.Browser.IsMobileDevice.但这实际上是如何工作的?我什至没有 .browser 文件……这里的幕后情况是什么?ASP.NET 2.0 是否有一些内置默认值?

Actually, it looks like you can also just check Request.Browser.IsMobileDevice. But how does this actually work? I don't even have a .browser file... what's going on behind the scenes here? Are there some built-in defaults for ASP.NET 2.0?

推荐答案

.NET 附带了许多 *.browser 文件:

A number of *.browser files are shipped with .NET:

C:WindowsMicrosoft.NETFrameworkv2.0.50727CONFIGBrowsers

运行时使用 *.browser 文件中的正则表达式来匹配传入的 User-Agent 字符串,然后根据它找到的每个匹配设置一组属性(层次结构中可以有多个).

The runtime uses regular expressions from the *.browser files to match against the incoming User-Agent string, and then sets a bunch of properties based on each match it finds (there can be several in the hierarchy).

如果您需要深入的移动设备支持,请考虑安装 MDBF,它增加了对大约 400 台设备的支持:

If you need in-depth mobile device support, consider installing the MDBF, which adds support for about 400 devices:

http://mdbf.codeplex.com/

这篇关于IsMobileDevice 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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