get 404 when trying to access files directly [duplicate]

回眸只為那壹抹淺笑 提交于 2019-12-20 06:30:30

问题


I have a WebApi project with a folder called "images".

I want to access the images directly but I keep getting 404 with message "No type was found that matches the controller named 'images'."

I did the same thing on MVC project and it always worked well, I don't know why in WebApi I can't access files.

I'm sure the file is there, I see it in the directory.

Example request: GET http://localhost:49873/images/20180704003126241.png


回答1:


Under a default configuration WebAPI won't serve static files for you. You need to either

  • Set up a controller on the WebAPI endpoint that will get the files and return a FileResult
  • Configure static file handling middleware

9 times out of 10 you'll want the second one. Note that the default configuration for Microsoft's static file middleware is to serve static content out of wwwroot so you'll probably need to put your images folder there.



来源:https://stackoverflow.com/questions/51163810/get-404-when-trying-to-access-files-directly

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