使用IApplicationBuilder.Map使用UseMvc生成嵌套路径 [英] Using IApplicationBuilder.Map generates nested paths with UseMvc
问题描述
我正在尝试将新的asp.net 5与VSNET 2015 RC一起使用.
I'm trying the new asp.net 5 alongside VSNET 2015 RC.
我的Web应用程序的配置: Microsoft.AspNet.Mvc 6.0.0-beta4
Configuration of my webapp: Microsoft.AspNet.Mvc 6.0.0-beta4
我对此行为感到非常困惑: 如果我使用
I'm really confused about this behavior: if i use
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.UseMvc();
}
一切正常.我通过以下方式致电我的控制器 http://localhost:1234/api/values 都可以.
everything works. I call my controller via http://localhost:1234/api/values and all is ok.
为了便于测试,我是否更改了
For the sake of my testing if i change the snippet above in
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
...
app.Map("/api", api => {
...
api.UseMvc();
});
}
现在,每次我使用上面的地址调用控制器时,该应用都会触发404.
and now every time I call the controller with the address above, the app returs 404.
我错了哪里?
推荐答案
在执行app.Map
时.您实际上正在做的是在HTTP管道中添加一个中间件,这就是说:当HTTP请求进入且与路径/api
匹配时,这就是我想要发生的事情.
When you're doing app.Map
. What you're actually doing is adding a middleware to your HTTP pipeline which is saying: when an HTTP request comes in that matches the path /api
here's what I want to happen.
您然后说的是:我希望当请求满足/api
路由时运行MVC.由于配置是嵌套的,因此控制器的新路径变为: http://localhost:1234/api/api/值.
You're then saying: I want MVC to run when a request satisfies the /api
route. Since the configurations are nested the new path to your controller becomes: http://localhost:1234/api/api/values.
希望这会有所帮助!
这篇关于使用IApplicationBuilder.Map使用UseMvc生成嵌套路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!