我想将路由配置与asp.net核心中的启动分开吗?
.net核心中的默认设置:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
最佳答案
您可以使用以下代码:
public static class RouteConfig
{
public static IRouteBuilder Use(IRouteBuilder routeBuilder)
{
//eg sample for defining Custom route
//routeBuilder.MapRoute("blog", "blog",
// defaults: new { controller = "Home", action = "Index" });
routeBuilder.MapRoute(name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
return routeBuilder;
}
}
并在启动和配置方法中:
app.UseMvc(c => RouteConfig.Use(c));
关于c# - 如何将路由配置与asp.net核心中的启动分开?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51818461/