sindrem
sindrem

Reputation: 1231

How to target mobile devices to a project

I got solution now in Visual Studio with 2 web projects. One default, and one i would like to target if the user is using a mobile device.

I would like to check if the user is on a mobile device when entering the default site, www.site.com, then redirect to the m.site.com.

How can this be done?

Upvotes: 0

Views: 103

Answers (1)

sohel khalifa
sohel khalifa

Reputation: 5578

[1]

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");          
    }
} 

[2]

Another better method is to use open source project called 51Degrees. Here is an article about how to use it in your application.

Upvotes: 1

Related Questions