Here is how to test for mobile browsers on your ASP.NET website:
1) Download the Mobile Browser Definition file from Codeplex at http://mdbf.codeplex.com/
2) Add an App_Browsers folder to your website. Add a new folder to the App_Browsers folder (you can name it “Devices” or whatever), and place the mobile.browser file you downloaded from Codeplex in the folder:
3) Add the following code to your Default.aspx code-behind:
protected void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
HttpBrowserCapabilities bc = Request.Browser;
if (bc.IsMobileDevice)
{
Response.Redirect("http://m.yourmobileversion.com");
}
}
}
No comments:
Post a Comment