This question already has an answer here:
这个问题在这里已有答案:
- Mobile Device Detection in asp.net 7 answers
asp.net 7中的移动设备检测答案
I have an existing web site and I would like to create a mobile version of it that is more suitable. For instance, the main site uses drop-down menus and we all know those are quite the fail on mobile devices.
我有一个现有的网站,我想创建一个更适合的移动版本。例如,主站点使用下拉菜单,我们都知道这些都是移动设备上的失败。
I would like to redirect to my mobile version (it will be a subdomain of the current site) if I detect a request from a mobile browser. So when they Google something and come to my site, they will automatically see the mobile version (just like Wikipedia).
如果我检测到来自移动浏览器的请求,我想重定向到我的移动版本(它将是当前网站的子域)。所以当他们谷歌的东西来到我的网站时,他们会自动看到移动版本(就像*一样)。
Does ASP.NET provide an easy way of doing this? If not, how can I do it?
ASP.NET提供了一种简单的方法吗?如果没有,我该怎么办?
5 个解决方案
#1
3
You can use the IsMobileDevice property somewhere in the Request.Browser. You need some decent browser definitions though. I use these excellent set of browser definitions: Ocean's place browser definitions.
您可以在Request.Browser中的某处使用IsMobileDevice属性。你需要一些不错的浏览器定义。我使用这些优秀的浏览器定义:Ocean的位置浏览器定义。
They are really in depth and the best I've seen. I think he is currently working on .NET4 ones too.
他们真的是深度和我见过的最好的。我认为他目前也在研究.NET4。
#2
3
I think the best solution is WURFL. It is more up date device description repository and it is free. The only inconvenience is .net api is GPL.
我认为最好的解决方案是WURFL。它是更新的设备描述存储库,它是免费的。唯一的不便是.net api是GPL。
#3
3
Keep it simple...
把事情简单化...
Heres the JS for the same...
继续JS的同样......
Hope it helps someone..
希望它可以帮助某人..
var useragent = navigator.userAgent;
var isMobile = !!useragent.match(/iPhone|Android|Blackberry|Sony|Nokia|Motorola|Samsung/i),
isWebBrowser = !!useragent.match(/Mozilla/i);
// Redirect the call accordingly.
if(isWebBrowser && !isMobile)
//call to web portal
alert(" You seem to me... calling from Web Browser")
else if(isMobile)
//call to mobile apps
alert(" Call seems to be from Mobile device...")
else
{
// jus kiddin...
alert(" Unable to detect the device..... Please report to admin...")
}
#4
2
There is a project on codeplex that you can use : Mobile Device Browser File
您可以使用codeplex上的项目:移动设备浏览器文件
Project Description
The Mobile Browser Definition File contains definitions for individual mobile devices and browsers. At run time, ASP.NET uses the information in the request header to determine what type of device/browser has made the request.
移动浏览器定义文件包含各个移动设备和浏览器的定义。在运行时,ASP.NET使用请求标头中的信息来确定发出请求的设备/浏览器的类型。
This project provides a data file that when used with ASP.NET will detect the incoming mobile device and present you as the web developer with a set of 67 capabilities or properties describing the requesting device. These capabilities range from screen size to cookie support and provide all the information you need to adaptively render content for mobile phones and devices.
此项目提供的数据文件与ASP.NET一起使用时将检测传入的移动设备,并将您作为Web开发人员提供一组描述请求设备的67个功能或属性。这些功能包括屏幕大小和cookie支持,并提供自适应地为移动电话和设备呈现内容所需的所有信息。
What is the Mobile Device Browser Definition File?
什么是移动设备浏览器定义文件?
The Mobile Device Browser Definition File contains capability definitions for individual mobile devices and browsers. At run time, ASP.NET uses this .browser file, along with the information in the HTTP request header, to determine what type of device/browser has made the request and what the capabilities of that device are. This information is exposed to the developer through the Request.Browser property and allows them to tailor the presentation of their web page to suit the capabilities of the target device.
移动设备浏览器定义文件包含各个移动设备和浏览器的功能定义。在运行时,ASP.NET使用此.browser文件以及HTTP请求标头中的信息来确定请求的设备/浏览器类型以及该设备的功能。此信息通过Request.Browser属性向开发人员公开,并允许他们定制其网页的表示以适应目标设备的功能。
#1
3
You can use the IsMobileDevice property somewhere in the Request.Browser. You need some decent browser definitions though. I use these excellent set of browser definitions: Ocean's place browser definitions.
您可以在Request.Browser中的某处使用IsMobileDevice属性。你需要一些不错的浏览器定义。我使用这些优秀的浏览器定义:Ocean的位置浏览器定义。
They are really in depth and the best I've seen. I think he is currently working on .NET4 ones too.
他们真的是深度和我见过的最好的。我认为他目前也在研究.NET4。
#2
3
I think the best solution is WURFL. It is more up date device description repository and it is free. The only inconvenience is .net api is GPL.
我认为最好的解决方案是WURFL。它是更新的设备描述存储库,它是免费的。唯一的不便是.net api是GPL。
#3
3
Keep it simple...
把事情简单化...
Heres the JS for the same...
继续JS的同样......
Hope it helps someone..
希望它可以帮助某人..
var useragent = navigator.userAgent;
var isMobile = !!useragent.match(/iPhone|Android|Blackberry|Sony|Nokia|Motorola|Samsung/i),
isWebBrowser = !!useragent.match(/Mozilla/i);
// Redirect the call accordingly.
if(isWebBrowser && !isMobile)
//call to web portal
alert(" You seem to me... calling from Web Browser")
else if(isMobile)
//call to mobile apps
alert(" Call seems to be from Mobile device...")
else
{
// jus kiddin...
alert(" Unable to detect the device..... Please report to admin...")
}
#4
2
There is a project on codeplex that you can use : Mobile Device Browser File
您可以使用codeplex上的项目:移动设备浏览器文件
Project Description
The Mobile Browser Definition File contains definitions for individual mobile devices and browsers. At run time, ASP.NET uses the information in the request header to determine what type of device/browser has made the request.
移动浏览器定义文件包含各个移动设备和浏览器的定义。在运行时,ASP.NET使用请求标头中的信息来确定发出请求的设备/浏览器的类型。
This project provides a data file that when used with ASP.NET will detect the incoming mobile device and present you as the web developer with a set of 67 capabilities or properties describing the requesting device. These capabilities range from screen size to cookie support and provide all the information you need to adaptively render content for mobile phones and devices.
此项目提供的数据文件与ASP.NET一起使用时将检测传入的移动设备,并将您作为Web开发人员提供一组描述请求设备的67个功能或属性。这些功能包括屏幕大小和cookie支持,并提供自适应地为移动电话和设备呈现内容所需的所有信息。
What is the Mobile Device Browser Definition File?
什么是移动设备浏览器定义文件?
The Mobile Device Browser Definition File contains capability definitions for individual mobile devices and browsers. At run time, ASP.NET uses this .browser file, along with the information in the HTTP request header, to determine what type of device/browser has made the request and what the capabilities of that device are. This information is exposed to the developer through the Request.Browser property and allows them to tailor the presentation of their web page to suit the capabilities of the target device.
移动设备浏览器定义文件包含各个移动设备和浏览器的功能定义。在运行时,ASP.NET使用此.browser文件以及HTTP请求标头中的信息来确定请求的设备/浏览器类型以及该设备的功能。此信息通过Request.Browser属性向开发人员公开,并允许他们定制其网页的表示以适应目标设备的功能。