Thursday, March 15, 2007

This bit of ASP.Net C# code, I love.    Put this in the root of your website in a page called default.aspx

It redirects mobile users to one place and normal (i.e desktop browsers to another).   Simple but really does the trick.

 

 

<%@ Page Language="C#" Trace="false" %>

<SCRIPT LANGUAGE="C#" RUNAT=SERVER>

protected void Page_Load(Object sender, EventArgs e)
{
System.Web.Mobile.MobileCapabilities cur = (System.Web.Mobile.MobileCapabilities) Request.Browser;

// this block of code is to detect if users are running Pocket PC 2003
bool isce=false;

try {
isce = (Request.UserAgent.IndexOf("Windows CE")!=-1);
}
catch
{

}
if (cur.IsMobileDevice||isce)
{
Response.Redirect("mobile"); // MOBILE HOME PAGE
}
else
{
Response.Redirect("main"); // NORMAL HOME PAGE
}
}

</SCRIPT>

Comments are closed.

Theme design by Jelle Druyts

Pick a theme: