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

标签 c# .net asp.net-core .net-core-3.0 asp.net-core-3.1

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

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

最佳答案

在 .NET 3 中你应该使用 端点 而不是 路由

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?}");
});

关于c# - 如何在 ASP.NET Core 3.1 MVC 中进行自定义路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59223635/

相关文章:

c# - Windows 窗体标签大小调整问题

c# - 在实现自己的 IUserStore 时,类上的 "optional"接口(interface)实际上是可选的吗?

c# - 在 C# 中选择 MySQL 数据

c# - 使用 PropertyInfo 找出属性类型

asp.net-core - 新的 ASP.NET 5 预览项目无法运行

javascript - 如何在 ASP.Net Core MVC 中创建级联 SelectList

c# - 没有为类型定义无参数构造函数.. Ajax JQuery 调用时出错

.net - 如何分析 .net 垃圾收集器?

.net - SQLite 数据库允许的最大大小是多少,我可以使用 PetaPoco 作为 ORM 吗?

asp.net-core - 使用自定义位置时如何在asp.net core mvc中指定 View 位置?