ASP.NET MVC Area does not select the correct route

I am in the process of debugging a routing problem in my MVC 3 application, and I am using the Phil Hacks routing debugger.

I can’t understand where the route marked in yellow below starts from. Every time I run my application with the following request

http://www.mywebsite.com/auth/login?ReturnUrl=/

this route goes first and then gives me a 404 error since I have no index action. As you can see, I set the default routes for using the login action method, but this route is saved.

enter image description here

I have the following route configurations:

AuthAreaRegistration

public class AuthAreaRegistration : AreaRegistration { public override string AreaName { get { return "Auth"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "login", "auth/login/{*returnPath}", new { controller = "Auth", action = "LogIn", id = UrlParameter.Optional } ); context.MapRoute( "Auth_default", "Auth/{controller}/{action}/{id}", new { controller = "Auth", action = "LogIn", id = "" } ); } } 

Global.asax (using T4 MVC templates)

  public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Home", "{controller}/{action}/{id}", MVC.Home.Index(), new { id = UrlParameter.Optional }, new string[] { "MyNamespace.WebUI.Controllers" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", MVC.Home.Index(), new { id = UrlParameter.Optional }, new string[] { "MyNamespace.WebUI.Controllers" } ); } 
0
source share
2 answers

I do not want to answer my question, but after I tried to solve this problem, I thought that I would send an answer if someone else would have the same problem.

It turned out that my application keeps on old routes and fills them into my route collection. I deleted all the files in the bin folder and rebuilt my solution, and everything worked as it should.

I answered this question in a little more detail:

Does ASP.NET MVC create default routes for regions

+1
source

I think the problem is that you have an area called Auth and a controller called Auth outside the areas.

MVC will first try to map your URL to an Auth realm, but you really want it to hit your authorization controller outside the realm.

The best way to solve this is imho - to avoid ambiguous controller / scope names.

0
source

Source: https://habr.com/ru/post/1337932/


All Articles