0

I have 3 areas at the moment (more will come when I get this working): Login, User and Admin. The Default route in Global.asax go to the index action of the index controller in the login area (Login\Index\Index) which works fine, this is how I mapped that:

routes.MapRoute(
    "Default", // Route name
    "{area}/{controller}/{action}/{id}", // URL with parameters
    new { area = "Login", controller = "Index", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
    new[] { typeof(AppName.Areas.Login.Controllers.IndexController).Namespace }
); 

each of the 3 areas is registered like this in the AreaRegistration files:

context.MapRoute(
    "Admin_default",
    "{area}/{controller}/{action}/{id}",
    new { area = "Admin", controller = "Index", action = "Index", id = UrlParameter.Optional },
    new[] { typeof(AppName.Areas.Admin.Controllers.IndexController).Namespace }
);

The Login controllers index action takes the users login details, looks up the type of user and redirects them to the appropriate area...... at least it should do. From what I can gather searching google, the correct way to redirect to a specific area is this:

return RedirectToAction("Action", "Controller", new { area = UserType });

which doesn't seem to work, it just redirects to Login\Controller\Action and I can't work out why.

In my attempts to work out what was happening I used this:

var url = Url.Action("Action", "Controller", new { area = "Admin" });

which produced the same Login\Controller\Action url.

Any help fixing this would be greatly appreciated

Ben
  • 5,525
  • 8
  • 42
  • 66

1 Answers1

0

In the routes parameter, you just set new { area = "OtherAreaName" }.

EDIT

Oh, I see you already tried that. I suppose the name of that area is correctly referenced and correctly named in the class AreaRegistration class, like this?

public class AuthorAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "Author";
        }
    }

    // ...
}

Could it also be that you need authentication and you are being redirected to the login page?

Fabio Milheiro
  • 8,100
  • 17
  • 57
  • 96
  • oh and authentication is required, but when that fails it redirects to the login with the requested url in the query string so it knows where to go once they log back in, and thats not happening so i know its not an authentication problem – Ben Nov 22 '12 at 10:36
  • Not following. If you have a returnUrl in the query string, why not check the login action. After logging in successfully, it needs to make use of the returnUrl argument. If not using, change it to start using – Fabio Milheiro Nov 22 '12 at 13:12
  • my point is, that when authentication fails you end up with a url in the query string, but when i redirect to another area and i end up on the login screen there is no arguments in the querystring, suggesting that it was not an authentication failure sending me back to the login screen – Ben Nov 22 '12 at 15:19