尝试直接访问文件时得到404 [英] get 404 when trying to access files directly

查看:175
本文介绍了尝试直接访问文件时得到404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebApi项目,其中有一个名为 images的文件夹。

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

我想直接访问图像,但不断收到消息404,提示否发现类型与名为'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'."

我在MVC项目上做过同样的事情,并且总是运行良好,我不知道为什么在WebApi中我无法访问文件。

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.

示例请求:GET http:// localhost:49873 / images / 20180704003126241 .png

推荐答案

在默认配置下,WebAPI不会为您提供静态文件。您需要

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


  • 在WebAPI端点上设置一个控制器,该控制器将获取文件并返回 FileResult

  • 配置静态文件处理中间件

9次(共10次)您需要第二个。请注意,Microsoft静态文件中间件的 default 配置用于提供 wwwroot 之外的静态内容,因此您可能需要将images文件夹放在此处

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.

这篇关于尝试直接访问文件时得到404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆