Detecting a mobile browser in ASP.NET
来源:互联网 发布:java encodeuri工具类 编辑:程序博客网 时间:2024/05/16 14:58
// Declare a boolean variable for mobile browser
bool IsMobi = false;
if (Request.Headers["X-Wap-Profile"] != null)
{
if (Request.Headers["X-Wap-Profile"].ToString().Length > 0)
{
IsMobi = true;
Response.Redirect("index.aspx", true);
}
Else
{
Response.Redirect("web/index.aspx", true);
}
}
{
//GETS THE CURRENT USER CONTEXT
HttpContext context = HttpContext.Current;
if (context.Request.Browser.IsMobileDevice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains("wap"))
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
{
//Create a list of all mobile types
string[] mobiles =
new[]
{
"midp", "j2me", "avant", "docomo",
"novarra", "palmos", "palmsource",
"240x320", "opwv", "chtml",
"pda", "windows ce", "mmp/",
"blackberry", "mib/", "symbian",
"wireless", "nokia", "hand", "mobi",
"phone", "cdm", "up.b", "audio",
"SIE-", "SEC-", "samsung", "HTC",
"mot-", "mitsu", "sagem", "sony"
, "alcatel", "lg", "eric", "vx",
"NEC", "philips", "mmm", "xx",
"panasonic", "sharp", "wap", "sch",
"rover", "pocket", "benq", "java",
"pt", "pg", "vox", "amoi",
"bird", "compal", "kg", "voda",
"sany", "kdd", "dbt", "sendo",
"sgh", "gradi", "jb", "dddi",
"moto", "iphone"
};
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVariables["HTTP_USER_AGENT"].
ToLower().Contains(s.ToLower()))
{
return true;
}
}
}
}
- Detecting a mobile browser in ASP.NET
- Detecting a mobile browser in ASP.NET
- Javascript detecting a mobile browser
- Detecting Designmode in ASP.Net
- Detecting ASP.NET Session Timeouts
- A Markdown implement in browser
- Understanding Pagination in ASP.NET 1.x Mobile Applications
- Detecting Faces in Images: A Survey( 翻译)
- iOS: Detecting which UIButton was pressed in a UITableView
- stopping popup windows in a web browser
- Disable HTML a links in different browser
- Detecting event support without browser sniffing
- 自定义asp.net mobile control
- ASP.NET MOBILE开发体会
- what happens when you type in a URL in browser
- How to Confirm a Delete in an ASP.NET Datagrid...
- ASP.NET in a Nutshell, Second Edition [ILLUSTRATED]
- Convert a DataReader to DataTable in ASP.NET
- linux ftp命令参数及使用方法全集
- IPhone的界面切换方法
- JSP本质
- QNX下交叉编程的实现
- 关于炒股的一点认识
- Detecting a mobile browser in ASP.NET
- zoj 2504 Help John!(Dijkstra~~)
- UE的正则表达式
- c++调用自定义的dll
- Iphone数组一些基础操作 NSArray/NSMutableArray
- iphone关于self.用法的一些总结
- php的instanceof
- WPF的窗口
- Using KGDB debug linux kernel and kernel module