public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
HttpBrowserCapabilities bc = context.Request.Browser;
//context.Response.Write("<p>Browser Capabilities:</p>");
//context.Response.Write("Type = " + bc.Type + "<br>");
//context.Response.Write("Name = " + bc.Browser + "<br>");
//context.Response.Write("Version = " + bc.Version + "<br>");
//context.Response.Write("Major Version = " + bc.MajorVersion + "<br>");
//context.Response.Write("Minor Version = " + bc.MinorVersion + "<br>");
//context.Response.Write("Platform = " + bc.Platform + "<br>");
//context.Response.Write("Is Beta = " + bc.Beta + "<br>");
//context.Response.Write("Is Crawler = " + bc.Crawler + "<br>");
//context.Response.Write("Is AOL = " + bc.AOL + "<br>");
//context.Response.Write("Is Win16 = " + bc.Win16 + "<br>");
//context.Response.Write("Is Win32 = " + bc.Win32 + "<br>");
//context.Response.Write("Supports Frames = " + bc.Frames + "<br>");
//context.Response.Write("Supports Tables = " + bc.Tables + "<br>");
//context.Response.Write("Supports Cookies = " + bc.Cookies + "<br>");
//context.Response.Write("Supports VB Script = " + bc.VBScript + "<br>");
//context.Response.Write("Supports JavaScript = " + bc.JavaScript + "<br>");
//context.Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>");
//context.Response.Write("Supports ActiveX Controls = " + bc.ActiveXControls + "<br>");
//context.Response.Write("CDF = " + bc.CDF + "<br>");
//context.Response.Write(bc.SupportsXmlHttp);
//context.Response.Write(HttpContext.Current.Request.UserAgent + "<br>");
string ss = HttpContext.Current.Request.UserAgent;
context.Response.Write(ss+"<br>");
string m = "mobile";
int res= ss.ToLower().IndexOf(m, , ss.Length);
if (res<=)
{
context.Response.Write("Pc端");
}
else
{
context.Response.Write("你使用的是手机端");
} }

通过UserAgent获得客户端提交上来的消息,存储为字符串;

通过匹配字符串,如果字符串中包含mobile,则返回手机端,否则为PC端

05-07 12:52