62,046
社区成员
发帖
与我相关
我的任务
分享
public static bool GetClientWeb()
{
bool result = false;
string clientType = string.Concat(HttpContext.Current.Request.UserAgent);
if (clientType.ToLower().Contains("mozilla") || clientType.ToLower().Contains("opera"))
{
result = true;
}
return result;
}
/// <summary>
/// 判断手机用户UserAgent
/// </summary>
/// <returns></returns>
private bool IsMobile()
{
HttpContext context = HttpContext.Current;
if (context != null)
{
HttpRequest request = context.Request;
if (request.Browser.IsMobileDevice)
return true;
string MobileUserAgent=System.Configuration.ConfigurationManager.AppSettings["MobileUserAgent"];
Regex MOBILE_REGEX = new Regex(MobileUserAgent);
if (string.IsNullOrEmpty(request.UserAgent) || MOBILE_REGEX.IsMatch(request.UserAgent.ToLower()))
return true;
}
return false;
}
以下为web.config配置里边的
<add key="MobileUserAgent" value="iphone|android|nokia|symbian|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile|blackberry|windows ce|motorola|mqqbrowser|ucweb"/>