2

I had a .netcoreapp1.1 project.

Recently, I changed the version from .netcoreapp1.1 to .NET Core 6.0. After this change. I see this warning message:

warning : Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc'.

I understand that by setting EnableEndpointRouting to false I can solve the issue, but I need to know what is the best way to solve it and why Endpoint Routing does not need UseMvc() function.

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggingBuilder builder)
{
    builder.AddConfiguration(Configuration.GetSection("Logging"));
    builder.AddConsole();
    builder.AddDebug();
    app.UseDefaultFiles();
    app.UseStaticFiles();
    app.UseMvc();
}
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
user
  • 47
  • 4
  • You can have a look at [App startup in ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-6.0) . – Qing Guo Jul 24 '23 at 09:23
  • 3
    Quite a lot of things has changed since the ASP.NET Core 1.1. Try creating an MVC app from template and check out how it works. For more detailed view of changes you can go through the upgrade guides starting from [Migrate from ASP.NET Core 1.x to 2.0](https://learn.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/?view=aspnetcore-7.0) – Guru Stron Jul 24 '23 at 09:27
  • I think this is what you're looking for: https://stackoverflow.com/questions/57684093/using-usemvc-to-configure-mvc-is-not-supported-while-using-endpoint-routing – Kwok He Jul 24 '23 at 09:32
  • 1
    @KwokHe it is also a bit dated, `app.UseEndpoints` is not needed AFAIK. – Guru Stron Jul 24 '23 at 09:43
  • 1
    @GuruStron You're right – Kwok He Jul 26 '23 at 08:35

1 Answers1

4

The main part of the changes related to routing set up is covered in the Migrate from ASP.NET Core 2.2 to 3.0 (and in this part too, and this). Though the suggested change from UseMvc to app.UseEndpoints(e => {e.MapControllerRoute ... is a bit dated too, in .NET 6 you can just do:

app.UseRouting();

// ...

// route from the default template:
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

Note that depending on what MVC features you are using you might want still to use the previous approach and set EnableEndpointRouting to false on early migration stages (for example).

Read more:

Guru Stron
  • 102,774
  • 10
  • 95
  • 132