Search code examples
c#asp.net-mvcasp.net-coreurl-routing

Why is the Home Controller's Index action not being hit when program starts up?


When I start my ASP.NET MVC application up, it does not hit the HomeController's Index action, but when I explicitly type the URL Home/Index, it works as expected.

Here is how the end point is set up in Startup.cs:

app.UseEndpoints(endpoints =>
        {
            // endpoints.MapControllers();
            endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

            // Blazor
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapBlazorHub();
        });

Solution

  • Try to change the below code in your _Host.cshtml

    @page "/"
    

    into

    @page ""
    

    result:

    enter image description here