Some of our site's images are "private" and should only be served to authenticated and authorized users.
So they are located in /App_Data
, and are rendered via this secured action:
//[ChildActionOnly]
[Authorize]
[HttpGet]
[Route("Image")]
public virtual FileResult Image(string path) {
return base.File(Server.MapPath(path), "image/jpg");
}
In a view, I have <img src="@Url.Action(Image(...))">
which correctly serves that "private" image. No public user can see it.
Problem is I don't want my authenticated users to be able to navigate to it directly, so I added the [ChildActionOnly]
attribute. But when I do that, it fails to load.
How can I serve these images to private users, but make it inaccessible from a request?