Sunday, January 16, 2011

Detecting Platform on a Device in ASP.NET

This code will determine the platform in .NET and based on the it will display the respective logo. I used this for my MobileExec 2011 program.



string strUserAgent = Request.UserAgent.ToString().ToLower();


            if (strUserAgent != null)
            {
                if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
                    strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
                    strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
                    strUserAgent.Contains("palm"))
                {
                    Response.Redirect("Default.aspx");
                }
            }

No comments:

Post a Comment