April 26, 2017

C# Server Side Mobile Web Browser Detection and Redirection

In Page_Load event of the codebehind file (e.g., samplepage.aspx.cs). To enable this site-wide, just add it to the Page_Load event of the Master Page file or in the main default.aspx page..

if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" || Request.Browser["BlackBerry"] == "true" || Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC")) || Request.UserAgent.ToLower().Contains("iphone"))
{
Response.Redirect("http://mobile.nwds-ak.com");
}

Thanks to blog.abwebsitedesign.com)

Alternate Solutions to Consider