我有两种方法的控制器
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。 我没有实现任何身份验证,所有文件都在同一台计算机上。