Make a page which will get the ressource, like if using Webforms could be GetGraphics.aspx?ressourceid=mypicture.png which then requires an active session or a cookie.
If you use mvc you can do the same thing with routing ... which ultimately can also be set in place in web.forms like for instance
public class UriActionFilter : System.Web.Mvc.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
{
if (System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated)
{
var user = System.Threading.Thread.CurrentPrincipal.Identity.Name;
var ctxParams = filterContext.ActionParameters;
filterContext.RequestContext.HttpContext.Response.StatusCode = 403;
return;
}
base.OnActionExecuting(filterContext);
}
}
Which i picked up as a reply here:
c# - ASP .NET MVC - files access - Stack Overflow[
^]