'How do I make a scaffolded page the first page

So I'm following the get started tutorial on ASP.NET . So far so good, however going to /controllerName is quite tedious. Is there a way how I can go to that index page on start up of the project? I couldn't find it in the walkthrough or any documentation. I'm using version 6.0 . I'm sorry for this basic question.



Solution 1:[1]

.NET MVC has built in defaults that can be overriden.

The default start page which will be routed from the root / is the Index action on the home controller:

public class HomeController : 
{
    public IActionResult Index()
    {
        // ...
    }
}

Sticking to these defaults is a good idea so other developers will find it easier to make sense of your project.

But you can override the defaults in .NET 5.0 if you wish in the Startup.cs Configure method:

app.UseEndpoints(routes =>
{
    routes.MapControllerRoute(
        name: "default",
        pattern: "{controller=MyDefaultController}/{action=MyDefaultActionMethod}/{id?}");
    });
}

Solution 2:[2]

You can change the desired starting page from Route config. It's in App_Start>RouteConfig route config

You can change it controller name and index page as you want.

public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controllerName}/{actionName}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Richard Garside
Solution 2 Hgrbz