我想将路由配置与asp.net核心中的启动分开吗? 在.net核心中默认为:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
答案 0 :(得分:6)
您可以使用以下代码:
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));