How to set default page in ASP.NET Core MVC and .NET 5?

Viewed 214

I have created an ASP.NET Core MVC project running on .NET 5. I'm using areas in the project. I have created an area named StaffAug.

How can I set the view Login/Index in StaffAug area as default page?

3 Answers

Try this in your startup.cs file for default page:-

 app.UseEndpoints(endpoints =>
{

    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{area=StaffAug}/{controller=Login}/{action=Index}/{id?}"
    );

});

For that, now your default page is Index view in your Login controller.

On Solution Explorer right click your solution (project name) and select properties.

Then click on Web, on Start Action select Spcific Page and the View you want to be your home page.

If you are running the project locally and you only need to modify the default page, you can do so.

Open launchSettings.json and add the launchUrl path:

  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "test",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }

Automatically jump to https://localhost:44343/test/index default page when the project starts.

Related