I have a MVC3 web application with one default area and one admin area. Both have their won home pages after logging in. After successfully logging in to the application if i try to access the admin area i am getting InvalidRouteException.
Scenario is like that i login to the application successfully. When i try to access the admin area using
http://localhost/admin
i get following exception.
Server Error in '/' Application.
{controller}/{action}/{id} { controller: 'admin'; action: 'LogOn' } Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: LoginSystem.Web.Exceptions.InvalidRouteException: {controller}/{action}/{id} { controller: 'admin'; action: 'LogOn' }
However if i log-out and then use URL like
http://localhost/admin
it takes me to the login page successfully.
Please suggest.
Below is my RegisterArea function for the consumer area.
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Consumer_default",
"Consumer/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }, new[] { "MyPortal.Web.Areas.Consumer.Controllers" }
);
context.MapRoute(
"Admin", // Route name
"Admin/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional }, new[] { "MyPortal.Web.Controllers" }// Parameter defaults
);
}
More Information - Update 1 After registering "Admin" Route i am able to move to the Logon page. My application has 2 areas Client and ADmin(this is default one.) Both areas are authenticated. Now the scenario is that i logged in to client module. While i am logged in, i did
http://localhost/admin
and reached the Logon page. But the issue is that now the url donot contain the Return URL. What should i do so that it contains returnurl.
In normal scenario when we are not logged in the Logon page opens with return url added to its url.
Please suggest.
localhost/adminwhen not logged on? - SilverlightFox