Created
February 20, 2012 23:25
-
-
Save mdarnall/1872247 to your computer and use it in GitHub Desktop.
FMMobile Device Redirect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web; | |
namespace TransCore.FMWebMobile.DeviceRedirect | |
{ | |
public class DeviceRedirectModule : IHttpModule | |
{ | |
const string COOKIE_NAME = "FMWebFullSite"; | |
private const string MOBILE_PATH = "/m"; | |
public void Dispose() | |
{ | |
} | |
public void Init(HttpApplication context) | |
{ | |
context.BeginRequest += DoYourThang; | |
} | |
private void DoYourThang(object sender, EventArgs e) | |
{ | |
var application = sender as HttpApplication; | |
if (application == null || ((!application.Request.Browser.IsMobileDevice) || (CookieExists(COOKIE_NAME)))) | |
return; | |
HttpContext.Current.Response.Redirect(MOBILE_PATH, true); | |
} | |
private bool CookieExists(string cookieName) | |
{ | |
bool exists = false; | |
HttpCookie httpCookie = HttpContext.Current.Request.Cookies[cookieName]; | |
if (httpCookie != null) | |
{ | |
exists = true; | |
} | |
return exists; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment