【发布时间】:2013-10-01 21:23:03
【问题描述】:
我正在使用来自 ASP.NET 5 RC 的属性路由,包含在 Visual Studio 2013 RC 版本中。
我希望根路径 / 能够通向规范的 /Home/Index 路径,但我找不到仅使用属性路由的方法。是否有可能,如果没有,如果我也在使用 OWIN SelfHost,我该怎么做?换句话说,我在WebApp.Start<T> 方法中手动设置了我自己的HttpConfiguration 类(其中T 在启动时调用了Configure(IAppBuilder) 方法),而不是通过RouteTable.Routes 对象。还是我应该通过RouteTable.Routes 对象?当我尝试它时,我没有太多运气......
编辑:这是我迄今为止尝试过的:
// normal Web API attribute routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultWeb",
routeTemplate: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
下面的第二次尝试看起来有点可疑,因为不清楚我的 HttpConfiguration 对象与静态 RouteTable.Routes 对象的关系:
// normal Web API attribute routes
config.MapHttpAttributeRoutes();
RouteTable.Routes.MapRoute(
name: "DefaultWeb",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
【问题讨论】:
标签: asp.net-mvc asp.net-mvc-routing self-hosting visual-studio-2013 owin