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.
- 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.