简体   繁体   English

在ASP.NET中检查用户浏览器的最佳方法是什么?

[英]What is the best way to check the user's browser in ASP.NET?

What is the best way to check if the user is using a mobile browser? 检查用户是否正在使用移动浏览器的最佳方法是什么? I have seen some code, is the best way really thousands of if(...|| ...||) statements or is there a good api, if so which api does the job best(and for free preferably). 我看过一些代码,这是成千上万条if(... || ... ||)语句的最佳方式,或者是否有一个好的api,如果这样的话,api表现最好(最好是免费的)。 Thanks in advance. 提前致谢。

ps Am using c#, asp.net 3.5. ps我使用c#,asp.net 3.5。

The best thing to do it actually not detect the browser. 最好的做法实际上是不会检测到浏览器。 The number of browsers available, along with their various versions (and the likelihood of more coming along) means it isn't really practical to do. 可用的浏览器数量以及它们的各种版本(以及随之而来的更多版本)意味着这样做并不实际。 Even the number of devices has rocketed now that there are phones, tablets, netbooks and computers of all sizes. 现在有各种尺寸的电话,平板电脑,上网本和计算机,甚至设备的数量也猛增。

So instead of detecting a browser, grab the resolution of the device and use that... ie "This device is small, medium or large". 因此,不要检测浏览器,而是获取设备的分辨率并使用该分辨率……即“此设备是小型,中型或大型”。

If you need this information for document style, you can use device stylesheets. 如果您需要有关文档样式的信息,则可以使用设备样式表。

<link rel="stylesheet" href="standard.css" media="screen" type="text/css" />
<link rel="stylesheet" href="mobile.css" media="handheld" type="text/css"> 

More browsercap files can be found here: 在这里可以找到更多的browsercap文件:

http://owenbrady.net/browsercaps/ http://owenbrady.net/browsercaps/

You need to place them in the App_Browsers folder of your ASP.NET website then you can discover info about the client browser using Request.Browser , in particular: Request.Browser.IsMobileDevice 您需要将它们放置在ASP.NET网站的App_Browsers文件夹中,然后可以使用Request.Browser来发现有关客户端浏览器的信息,尤其是: Request.Browser.IsMobileDevice

I agree with @Sohnee that following this path is a maintenance hazard, but it can be useful for detecting spiders. 我同意@Sohnee的观点,遵循此路径是维护风险,但对于检测蜘蛛可能很有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ASP.NET中显示缩略图的最佳方法是什么? - What's the best way of displaying thumbnails in ASP.NET? 在 ASP.NET 上检测 JSON 请求的最佳方法是什么 - What's the best way to detect a JSON request on ASP.NET 设置用户输入数据的时间限制的最佳方法是什么? (asp.net mvc) - What is the best way to set time boundries for user to input data? (asp.net mvc) 为ASP.NET MVC Intranet应用程序实施Windows身份验证的最佳方法是什么? - What's the best way to implement Windows Authentication for an ASP.NET MVC intranet application? 什么是处理异常以及如何在asp.net中处理它们的最佳方法 - What's the best way to handle the exceptions and how to deal with them in asp.net 针对 ASP.NET REST Web ZDB974238714CA8DE63FZACE7服务器运行单元测试的最佳方法是什么 - What's the best way to run unit tests against an ASP.NET REST Web API server ASP.NET MVC - 从视图中创建 Url 到 controller 动作的最佳方法是什么? - ASP.NET MVC - What's the best way to create a Url to controller action from within view? 在ASP.Net应用程序中处理长时间运行的最佳方法是什么? - What's the best way to handle long running process in an ASP.Net application? 为ASP.NET MVC项目设置数据访问的最佳方法是什么? - What's the best way to set up data access for an ASP.NET MVC project? 使用Twitter Bootstrap在ASP.NET MVC中调用模式对话框的最佳方法是什么? - What's the best way to call a modal dialog in ASP.NET MVC using Twitter Bootstrap?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM