我创建了一个非常简单的模块,可以在媒体库的特定文件夹中显示图像。我登录到我的Orchard网站时效果很好,但图像不会显示给匿名用户。这是我的模块代码的简化版本:
public ActionResult Image(int id, int? width, int? height) {
var items = _mediaLibraryService
.GetMediaContentItems("Portfolio", 0, Int32.MaxValue, null, null);
var mediaItem = items.Where(i => i.Id == id).SingleOrDefault();
if (mediaItem == null) {
return null;
}
string imageFileName = Server.MapPath(mediaItem.MediaUrl);
string contentType = "image/" + Path.GetExtension(imageFileName).Substring(1);
// code to resize image based on given parameters ...
return File(imageFileName, contentType);
}
该操作接受MediaPart ID和维度,按ID查找项目,调整图像大小,并将其作为FileResult返回。这在登录时工作正常,但匿名用户什么也得不到。查看Chrome中的网络标签,显示响应长度为0.
当然,在本地测试时,我不会在我的实际网站上获得此行为。有什么想法吗?