需要更新 .NET Core 版本。

huangapple go评论58阅读模式
英文:

Need to update .NET Core version

问题

我有一个 .netcoreapp1.1 项目。

最近,我将版本从 .netcoreapp1.1 更改为 .NET Core 6.0。在这个变化之后,
我看到了这个警告消息:

警告:在使用终结点路由时,不支持使用 'UseMvc' 配置 MVC。要继续使用 'UseMvc',我理解可以通过将 EnableEndpointRouting 设置为 false 来解决问题,但我需要知道解决这个问题的最佳方式是什么,以及为什么 Endpoint Routing 不需要 UseMvc() 函数。

// 此方法由运行时调用。使用此方法配置 HTTP 请求管道。
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggingBuilder builder)
{
builder.AddConfiguration(Configuration.GetSection("Logging"));
builder.AddConsole();
builder.AddDebug();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseMvc();
}

英文:

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();
}

答案1

得分: 4

与路由设置相关的主要更改部分在Migrate from ASP.NET Core 2.2 to 3.0(以及此部分这部分)中有详细介绍。尽管从UseMvc建议更改为app.UseEndpoints(e => {e.MapControllerRoute ...也有点过时,在.NET 6中,您可以只需执行以下操作:

app.UseRouting();

// ...

// 使用默认模板路由:
app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

请注意,根据您正在使用的MVC功能,您可能仍然希望在早期迁移阶段使用先前的方法,并将EnableEndpointRouting设置为false(例如,示例)。

了解更多信息:

英文:

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:

huangapple
  • 本文由 发表于 2023年7月24日 17:18:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定