Web
Analytics
Use of app.UseMvcWithDefaultRoute() in asp.net core 3.1 | Angular | ASP.NET Tutorials

For Consultation : +91 9887575540

Stay Connected :

Use of app.UseMvcWithDefaultRoute() in asp.net core 3.1

Hello guys in this tutorial I am telling you how we can use the default route in ASP.NET core 3.1. As we know until asp.net Core 2.2 , if we have created a home controller and index action and want to open this as the default URL or root URL. In that case, we have to set a  middleware UseMvcWithDefaultRoute() which is responsible to call home controller and index action by default, but it does not work directly in ASP.NET core 3.x So in this case, if you want to implement that we have to disable endpoint routing by using configure services method in the startup.cs.

In ASP.NET one we have two types of routing the first one is convention routing and the second one is endpoint routing. Endpoint routing is not available in ASP.NET core 2.2 so we have to disable it in order to use UseMvcDefaultUrl.

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options => options.EnableEndpointRouting = false);
            services.AddControllersWithViews();            
        }

In configure request and response pipeline add following code

app.UseMvcWithDefaultRoute();