5
Il seguente codice è, auspicabilmente, un modo corretto per restituire un'immagine che è presente sul disco utilizzando ASP.NET MVC 3:ASP.NET MVC FilePathResult: come restituire un file html non trovato?
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 ???
}
Se non si trova il file, quello che si potrebbe tornare che rappresenterebbe un HTML Errore 404 (o equivalente?)