Mobile Device Detection ASP.NET
In ASP.NET, you can easily detect the mobile device request using Request.Browser.IsMobileDevice property and Request.UserAgent.
The following code checks the IsMobileDevice property and redirects to the mobile specific page:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Browser.IsMobileDevice)
{
Response.Redirec("~/default_mobile.aspx");
}
}
In MVC3 exposes an IsMobileDevice flag in the Request.Browser object.
So in your razor code, you can query this variable and render accordingly.
For example,
@if (Request.Browser.IsMobileDevice) {
HTML here for mobile device
} else {
HTML for desktop device
}
Comments
Post a Comment