0

I have encountered an issue in ASP MVC whereby I am attempting to access a View in the admin Area App/Areas/Admin/Account/Manage, however the page sometimes serves the user profile page in the root namespace controller App/Account/Manage.

It seems to be after I make a change to the admin View, but then works normally again after the debugger is restarted.

I am using RazorGenerator, so I suspect it's something to do with that, however I don't want to run the risk of another developer publishing the app without updating razor generator, and an admin having access to the users profile page.

All routes are being registered with AreaRegistration.RegisterAllAreas(); in the Global.asax file

The default route config includes the app namespace;

routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
  namespaces: new[] { "App.Controllers" }
);

And the admin area registration contains the routing;

context.MapRoute(
  name: "Admin_default",
  url: "Admin/{controller}/{action}/{id}",
  defaults: new { action = "Index", id = UrlParameter.Optional },
  namespaces: new[] { "App.Areas.Admin.Controllers" }
); 

I have setup a break point, and can follow the code through the Admin controller, however as soon as the return View(model) line is hit, it attempts to redirect to the user profile rather than the admin view.

Has anyone encountered something similar?

AranDG
  • 406
  • 4
  • 16
  • From your question it is not clear which route comes first. The 'Default' route should be the last in the route registration. – Rahatur Apr 04 '19 at 07:35
  • The default route is defined in the Global.asax file, whereas the Area routes are defined within their corresponding AreaRegistration.cs files – AranDG Apr 04 '19 at 07:38
  • Check the answers here: https://stackoverflow.com/questions/2140208/how-to-set-a-default-route-to-an-area-in-mvc – Rahatur Apr 04 '19 at 07:43

0 Answers0