using System.Text.RegularExpressions;//头部引入正则的命名空间
//为了加强准确性,防止支持wap的浏览器如opera,加入操作系统验证。openwave|后为pc操作系统
string osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Window|Longhorn|ubuntu|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS/2|OSF1|SUN";
string uAgent = Request.ServerVariables["HTTP_USER_AGENT"];
Regex reg = new Regex(osPat);
if (reg.IsMatch(uAgent))
{
Response.Write("电脑访问");
}
else
{
Response.Write("手机访问");
}
Response.Write("<br/>" + uAgent);
转载于:https://www.cnblogs.com/wwy224y/p/4730623.html
本文介绍了一种使用正则表达式来判断用户是否通过手机或电脑访问网站的方法。通过匹配用户代理字符串中的特定模式,可以准确地识别访问者的设备类型。
1081

被折叠的 条评论
为什么被折叠?



