Startup at . net core 2.2 and . net core 3.1

Asked

Viewed 297 times

0

I am taking the MVC core course from developer.io, but in the course . net core 2.2 is used and I am using version 3.1. In creating a MVC project from scratch the route configuration code in . netcore 2.2’s Startup.Cs is:

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

    //routes.MapRoute(
    //    name: "default",
    //    template: "{controller=Home}/{action=Index}/{id?}"
    //    )
});

And in . net core 3.1 is:

app.UseEndpoints(endpoints =>
{
    endpoints.MapGet("/", async context =>
    {
        await context.Response.WriteAsync("Hello World!");
    });
});

I tried to use the code of 2.2 in 3.1, but it’s not working because the code is already deprecated. I’d like to know the difference between the two codes, for example, why I use the endpoints.MapGet in 3.1. What was the change they made between . net core 2.2 and 3.1 in the Startup.cs?

1 answer

2


Hello, in the version of Core 3.0 or 3.1 the configuration is

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

The Mapget method is used to define an endpoint. A endpoint is something that can be: Selected by combining the URL and HTTP method.

You can read more about it here: https://aregcode.com/blog/2019/dotnetcore-understanding-aspnet-endpoint-routing/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.