0

I am enabling one of my sites to redirect certain pages to mobile versions. Ive read blog posts by Steve Sanderson and Shiju Varghese regarding Attribute usage and 51degrees.mobi.

What I would like to have happen is a given page, dealer-locator, redirect to /mobile/dealer-locator if the device is a mobile device. To accomplish this, I have set up an Area with the dealerlocator controller and the necessary views. Ive tested the code directly and it seems to work properly.

When I visit the site from an actual device or FF with the user agent changed to iPhone 3.0, I get redirected to /mobile. Is there a simple way to map page routes to mobile routes?

I should mention that the site uses isapi_rewrite and the page in question has rules that map /dealer-locator to /dealerlocator and dealerlocator is a controller.

Ive also noticed that form posts don't appear to work properly so it does a get for now.

jason
  • 767
  • 2
  • 9
  • 24
  • 1
    You may want have a look on the MVC 4 beta which support mobiles. See more [here:](http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-4-mobile-features) – gdoron Dec 29 '11 at 16:35

1 Answers1

0

From Shiju Varghese's blog post (which your question mentions), the method of the RedirectMobileDevicesToMobileAreaAttribute class:

// Override this method if you want to customize the controller/action/parameters to which
// mobile users would be redirected. This lets you redirect users to the mobile equivalent
// of whatever resource they originally requested.
protected virtual RouteValueDictionary GetRedirectionRouteValues(RequestContext requestContext)
{
    return new RouteValueDictionary(new { area = "Mobile", controller = "Home", action = "Index" });
}

can be overridden to take care of this.

In his example, everything appears to be sent to ~/Mobile/Home/Index, but you can send the request anywhere. He's creating a new route table, equivelant to the one you'd define in Global.asax.cs for your non-mobile routes. You could either replace your entire route table, or loop through your existing routes and return a dictionary that only contains the mobile equivelants.

3Dave
  • 28,657
  • 18
  • 88
  • 151