Zac*_*ott 5 c# fileresult asp.net-mvc-3
希望以下代码是使用ASP.NET MVC 3返回磁盘上存在的映像的正确方法:
public FilePathResult GetThumbnail(string imageName)
{
if( !String.IsNullOrEmpty(imageName) &&
Regex.IsMatch(imageName, @"^p\d{10}.jpg$"))) ) // p0000000000.jpg
{
var homePath = Server.MapPath("~/Content/previews");
var imagePath = Path.Combine( homePath, imageName );
if( System.IO.File.Exists(imagePath) )
return this.File(imagePath, "image/jpeg");
}
return ???
}
Run Code Online (Sandbox Code Playgroud)
如果您没有找到该文件,您可以返回哪些代表HTML 404错误(或等效的?)
归档时间: |
|
查看次数: |
7201 次 |
最近记录: |