This blog is moved to
http://amalhashim.wordpress.com

Thursday, November 12, 2009

ASP.Net to Check whether request is coming from mobile device

For checking this use the following code

protected void Page_Load(object sender, EventArgs e)
{
if (Request.Browser.IsMobileDevice == true ||
Request.UserAgent.ToLower().Contains("iphone"))
{
Response.Redirect("DefaultIPhone.aspx");
}
}

The UserAgent property contains the data which tells from which device the request is coming. On problem with this approach is that there are lot of mobile devices and browsers which runs on mobile. One solution I found for this problem is by using a library called 51degrees.mobi.

No comments: