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

by Chris Arkwright | Saturday, July 25, 2009  

Mobile phone

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 give us some recognition, 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");       
}

 

 

 

Comments (1) -

WpaapNetherlandsWpaap said:

For windows phone 7: if (Request.UserAgent.ToLower().Contains("windows phone os"))

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading