无法访问存储在我的App_Data文件夹中的图像 [英] Unable to access images stored inside my App_Data folder
问题描述
我的asp.net mvc Web应用程序内部具有以下链接:-
I have the following link inside my asp.net mvc web application :-
<a href="~/App_Data/uploads/38.png">@Model.Name</a>
但是当我单击此链接时,出现以下错误:
But when I click on this link, I get the following error :
HTTP错误404.8-未找到
HTTP Error 404.8 - Not Found
请求过滤模块配置为拒绝URL中包含hiddenSegment部分的路径.
The request filtering module is configured to deny a path in the URL that contains a hiddenSegment section.
那是什么引起了这个问题,我该如何解决呢?
So what is causing this problem , and how I can solve it ?
谢谢
推荐答案
创建一个控制器(例如"Streamer")和操作(例如"StreamUploadedImage")以流式处理图像(该操作通常将返回FileResult).
Create a Controller (e.g. "Streamer") and Action (e.g. "StreamUploadedImage") that streams the image (the Action will typically return a FileResult).
更改网址以引用您的操作,将图片ID作为参数传递,例如(从内存中读取,因此语法可能不准确):
Change the url to reference your action, passing the image id as a parameter, e.g. (from memory so syntax may not be accurate):
@Html.ActionLink(Model.Name, "StreamUploadedImage", "Streamer", new {id = "38" })
一种替代方法是将上传的图片放在可以从客户端访问的位置,例如在内容"文件夹的子文件夹中:
An alternative would be to put the uploaded image in a location where it can be accessed from the client, e.g. in a subfolder of the Content folder:
<a href="~/Content/uploads/38.png">@Model.Name</a>
但是使用控制器可以给您更多的控制权,例如实施授权.
But using a controller gives you more control, e.g. to implement authorization.
这篇关于无法访问存储在我的App_Data文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!