1

I have just started exploring routing in ASP.Net Core 2.2 MVC. I took the default project template and just changed route.MapRoute to always default to LoginController under Views

ex: Account/LoginController.cs with an Index method.

routes.MapRoute(
                name: "default",
                template: "Account/{controller=Login}/{action=Index}");

I get an error when I hit https://localhost:44364 in the browser

But the controller gets called when i copy this https://localhost:44364/Account/Login in the browswer.

How can i make the default route https://localhost:44364 to always hit LoginController under AccountFolder.

This is a basic set up for any website with a login page. Could someone help me with this. I am wasting a lot of time here.

1 Answer 1

1

Use this:

routes.MapRoute(
                name: "default",
                template: "{controller=Account/Login}/{action=Index}");

The other way you could do it is use areas, however your project doesn't use them. If you do decide to use areas, this would be the code for route

routes.MapRoute(
      name: "default",
      template: "{area:Account}/{controller=Login}/{action=Index}/{id?}");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.