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:
Code:
System.Web.HttpBrowserCapabilities browser = Request.Browser;
if (browser.IsMobileDevice == true)
Label1.Text = “MY APP ASP.NET – MOBILE”;
else
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