asp.net安全图像对其他用户的静态请求?

Mik*_*keJ 3 asp.net security image

我在一个为每个特定用户生成动态图像的网站上工作.有时这些图像包含非常敏感数据的描述.最近,我们开始以形式查看属于不同用户的图像请求

HTTP://myapp/images/someuid/image1.jpg

显然,有人发现如果他们创建了正确的URL,他们可以访问其他用户的图像.我们将图像存储到文件系统以帮助减少带宽.

  • 我们怎样才能保护这个 - 某种http处理程序?

  • 是否有一种方法可以提供图像以利用o -f缓存而无需将其写入文件系统并让IIS执行脏工作?

Ant*_*nes 5

使用.ashx: -

TimeSpan maxAge = new TimeSpan(0, 15, 0); //!5 minute lifetiem.

context.Response.ContentType = "image/gif";
context.Response.Cache.SetCacheability(HttpCacheability.Private);
context.Response.Cache.SetExpires(DateTime.UtcNow.Add(maxAge));
context.Response.Cache.SetMaxAge(maxAge);
context.Response.Cache.SetLastModified(lastModified); // last modified date time of file
context.Response.WriteFile(filenameofGif);
Run Code Online (Sandbox Code Playgroud)

您可以包含所需的代码检查,以确保正确的用户访问映像.