如何在 ASP.NET Core 3.1 MVC 中进行自定义路由

LPL*_*PLN 4 .net c# asp.net-core .net-core-3.0 asp.net-core-3.1

我不能在 .NET Core 3.1 中使用像在 .NET Core 2.2 中那样的简单路由。

.NET Core 3.1 中路由的最后更改是什么?

Ham*_*loo 15

在 .NET 3 中你应该使用Endpoint而不是Routing

app.UseStaticFiles();
app.UseRouting();
//other middleware

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
    endpoints.MapRazorPages();
    endpoints.MapHub<MyChatHub>();
    endpoints.MapGrpcService<MyCalculatorService>();
    endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)