Detect mobile device in ASP.NET Web Forms

Currently, it is necessary to give relevance to mobile devices when we are developing an application web. In this article, I will show an example on how to detect a mobile device in ASP.NET Web Forms.

HttpCapabilitiesBase.IsMobileDevice Property gets a value indicating whether the browser is a recognized mobile device.

Property Value:

  • Type: System.Boolean
  • true if the browser is a recognized mobile device; otherwise, false. The default is true.

Example: I will show a short code based on visual c # about using this property.

Click in the top menu File -> New Project:


In the New Project dialog box, select Templates -> Visual C# and click ASP.NET Web Application, then, in the next step under ASP.NET Templates 4.5.2, click Web Forms:


Inside the principal form, paste the following code, which will serve to detect mobile devices:



System.Web.HttpBrowserCapabilities browser = Request.Browser;

if (browser.IsMobileDevice == true)

Label1.Text = “MY APP ASP.NET – MOBILE”;


Label1.Text = “MY APP ASP.NET – DESKTOP”;

And that’s it! This short code helps to detect whether the device is mobile or not.

This concludes Detect mobile device in ASP.NET Web Forms.

Looking for quality Windows Hosting? Look no further than Arvixe Web Hosting!

Happy Hosting

Tags: , , , , , , , , , | Posted under ASP .NET 4.0, WebsitePanel Tutorials | RSS 2.0

Author Spotlight

Rodolfo Hernandez

I like photography and reading books. Currently working for Arvixe as Elgg Community Liaison. Elgg Security Expert Web Security Expert CEO of UDP SW Social Web

Leave a Reply

Your email address will not be published. Required fields are marked *