ASP.NET MVC creates default routes for areas

I have several areas in my MVC 3 Auth and Users application. I use the Phil Haacks Route Debugging Tool to view a list of my routes and see which one is selected based on my URL.

However, there are several existing routes that I have not created either in my AreaRegistration file or in Globalasax, and I do not know where they came from or how to get rid of them. Routes are highlighted in yellow below.

You can also see that I created a default route in my Auth area (highlighted in green), which simply indicates the input action of my Auth controller. I debugged RouteTable and it is added when AreaRegistration.RegisterAllAreas (); method. However, it is not added to AreaRegistration, since it also went through this.

Does ASP.NET MVC add this default value, and if possible, will I delete it somehow?

enter image description here

+4
source share
3 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.

In the end, I got rid of all my areas from my application and just had the basic routing of Global.asax. When I started the application, I could see in the route debugger that the routes collection from the existing areas was still filled in the route collection. After trying many things, including deleting everything from my temporary ASP.NET files, communicating with IIS AppPools and clearing the browser data, I finally came across an answer.

I deleted everything from the bin folder in the folders of websites, made a recreation and low, and now, the routes disappeared. I restored my areas with the described configuration, and everything works as it should.

I have no idea why my MVC application kept and populated the old routes, but as soon as my bin was cleaned up and the new DLL files created everything I needed. If anyone knows why this might be then I would be very interested.

+5
source

Yes, each area has its own AreaRegistration file, which defines the area’s routes. Find it in the root folder of your region.

In the User area, browse to β†’ User β†’ UserAreaRegistration.cs

It should contain something like this:

public class UserAreaRegistration : AreaRegistration { public override string AreaName { get { return "User"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "User_default", "User/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } } 
+2
source

Have you renamed your project? It loads routes by reflection, possibly by scanning everything in the bin folder. Therefore, if you edited your code and changed the assembly name, you could easily get the old code and register these routes.

Jb

0
source

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


All Articles