You can place these images somewhere on a server where users do not have access (for example, to the ~/App_Data ) to prevent direct access to them, and then use the controller action to serve them. This action will be decorated with the Authorize attribute to allow only its authorized users:
[Authorize] public ActionResult Image(string name) { var appData = Server.MapPath("~/App_Data"); var image = Path.Combine(appData, name + ".png"); return File(image, "image/png"); }
and then:
<img src="@Url.Action("Image", "SomeController", new { name = "foo" })" alt="" />
Inside the view, you can also check if the user is checked before displaying the image.
source share