Using IApplicationBuilder.Map generates nested paths with UseMvc

…衆ロ難τιáo~ 提交于 2020-01-13 10:34:08

问题


I'm trying the new asp.net 5 alongside VSNET 2015 RC.

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();
 }

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();
       });
 }

and now every time I call the controller with the address above, the app returs 404.

Where I'm wrong?


回答1:


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.

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.

Hopefully this helps!



来源:https://stackoverflow.com/questions/31117608/using-iapplicationbuilder-map-generates-nested-paths-with-usemvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!