Skip to content

Instantly share code, notes, and snippets.

@mdarnall
Created February 20, 2012 23:25
Show Gist options
  • Save mdarnall/1872247 to your computer and use it in GitHub Desktop.
Save mdarnall/1872247 to your computer and use it in GitHub Desktop.
FMMobile Device Redirect
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