Search code examples
c#mobile51degrees

Redirecting to a mobile sub-domain using 51degrees


I'm using the 51degrees API for mobile redirection: http://51degrees.codeplex.com/

When a mobile device is detected, using 51degrees, I am able to redirect from from any desktop page to the mobile homepage using the 51degrees configuration only. I.e. http://www.mydomain.com/somepage to http://m.somepage.com/default.

What I am unable to do is redirect to the same page, i.e. from http://www.mydomain.com/somepage to http://m.somepage.com/somepaage.

Is it possible to redirect to the same page?


Solution

  • Option 1: Use 51degrees for the mobile detection part only and wire up the redirect yourself. Remove the <redirect> element from your web.config and try something like this in your Global.asax file:

    void Application_BeginRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Browser.IsMobileDevice)
        {
            Response.Redirect("http://m.mydomain.com" + Request.RawUrl);
        }
    }
    

    Option 2: In the <redirect> element in the web.config file, add the property originalUrlAsQueryString=true. This will send a query string called origUrl to the mobile homepage giving you the option to redirect to the mobile version of the requested page.