Search code examples
asp.net-coreasp.net-core-2.2

How to set default url or startup page in asp.net core 2.2


When i'm creating routing in asp.net core 2.2 with companyname and controller. My application shows 404 error for the following code when I hit F5.

app.UseMvc(route => { route.MapRoute("Default", "MyCompany/{controller=Home}/{action=Index}/{id?}"); });

If I enter the full path it is working.

If I remove MyCompany before the controller, It works fine.

Please help me to fix this issue.


Solution

  • Try to configure your routing to:

    app.UseMvc(routes =>
            {
                routes.MapRoute(
                   name: "startupRoute",
                   template: "/",
                   defaults: new { controller = "Home", action = "Index" }) ;
                routes.MapRoute(
                    name: "default",
                    template: "MyCompany/{controller=Home}/{action=Index}/{id?}");
            });