UPDATED: Mobile Web Browser Detection and Redirection in C# for ASP.net

by Chris Saturday, July 25 2009


Here is an updated version of the mobile web browser detection and redirection in C-Sharp (#C) for ASP.net. For this to work best, you should add it to the "Application_BeginRequest" event of the global.asax file, located in the root directory.

If you use it, please digg it, tweet it, or link to it. That's all we ask. Thanks!



//mobile device detection and redirection
if (Request.Headers["User-Agent"] != null)
{

     if (Request.Browser["IsMobileDevice"] != null && Request.Browser["IsMobileDevice"] == "true")
     Response.Redirect("http://mobile.abwebsitedesign.com");
           
     if (Request.Browser["BlackBerry"] != null && Request.Browser["BlackBerry"] == "true")
     Response.Redirect("http://mobile.abwebsitedesign.com");
           
     if (Request.UserAgent.ToLower().Contains("iphone"))
     Response.Redirect("http://mobile.abwebsitedesign.com");

     if (Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC"))
     Response.Redirect("http://mobile.abwebsitedesign.com");       

}


 

Tags: , , , ,

ASP.net | Microsoft

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About this Blog

This is a blog about web design and all things that are related to web design. Pertinent and relevant comments and/or questions are highly encouraged, but please be courteous and thoughtful of others whilest making comments.

If you have benefited from a post, please do the right thing and promote it. You can do this by linking to it, tweeting it, or digging it.

Thank you much.

Recent Comments

Comment RSS