c# - 为什么iis使用asp net mvc控制器文件流返回403错误代码
问题描述
我有一个控制器有两种方法
public ActionResult Index1(string c, string d)
{
string path = "some path";
if (System.IO.File.Exists(path))
{
var bytes = System.IO.File.ReadAllBytes(path);
return base.File(bytes, MimeMapping.GetMimeMapping(path));
}
path = "/assets/images/no.jpg";
return File(path, "application/jpeg", "no.jpg");
}
public ActionResult Index2(string c, string d)
{
string path = "some path";
string _nomefile = "some name";
string _mime = "";
if (System.IO.File.Exists(path))
{
return new FileStreamResult(new FileStream(path, FileMode.Open), _mime) { FileDownloadName = _nomefile};
}
path = "/assets/images/no.jpg";
return File(path, "application/jpeg", "no.jpg");
}
这被这样的视图使用
@foreach (var item in Model.OrderBy(x => x.Titolo))
{
<div class="col-md-3 col-sm-12 immagini margin-bottom-20">
<a class="image-hover" href="/Index1?c=@item.Immagine&d=N" data-toggle="tooltip" title="@item.Titolo - @item.Descrizione">
<img src="/Index1?c=@item.Immagine&d=M" alt="@item.Titolo"><br />
<span>@item.Descrizione</span>
</a>
</div>
}
问题是 IIS 使用这两种方法都返回一个间歇性的 403 禁止,这完全是随机的。在包含 30 个图像的列表中,不显示 3 或 4 个。我没有实施任何身份验证,所有文件都在同一台机器上。
解决方案
推荐阅读
- python - python中字符串变量名的numpy数组值
- google-cloud-platform - 发布/订阅主题的 GCP 服务帐户访问问题
- apache-spark - PYCHARM 中的 Spark-Avro 错误 [TypeError: 'RecordSchema' 对象不可迭代]
- tensorflow - 无法将 TensorBoard 安装为 Keras 回调
- python-3.x - 为什么 heapq.heapify 这么快?
- c# - 我无法更新绑定数据(仅在第一次更新)
- npm - NPM 登录无需手动输入用户名、密码和电子邮件
- javascript - 从 API 调用 Next.js 中子组件的数据
- google-cloud-platform - 未发送“Google 我的商家”推送通知用于问答
- flutter - 使用 --no-tree-shake-icons 意味着构建后不会出现图标