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);