asp.net - MVC5 Using Controller to serve images, value can not be null -
i'm new mvc , followed tutorial on loading local files webpage , while seems work others getting error.
public class imagescontroller : controller { // get: images public actionresult someimage(string imagename) { var root = @"c:\images\"; var path = path.combine(root, imagename); path = path.getfullpath(path); if (!path.startswith(root)) { // ensure serving file inside root folder // , block requests outside "../web.config" throw new httpexception(403, "forbidden"); } return file(path, "image/png"); } } the error i'm getting is:
an exception of type 'system.argumentnullexception' occurred in mscorlib.dll not handled in user code additional information: value cannot null.
and line highlights is:
var path = path.combine(root, imagename);
when using url.action() helper, property name in anonymous object has match name of parameter in action.
and in case:
@url.action("someimage", "images", new { imagename = "logo.png" })
Comments
Post a Comment