5
下面的代碼是希望以正確的方式返回磁盤上存在的圖像使用ASP.NET MVC 3:ASP.NET MVC FilePathResult:如何返回未找到的html文件?
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 ???
}
如果你沒有找到該文件,你能有什麼回報,將代表HTML 404錯誤(或等效?)