IIS虚拟目录获取带有过期的预签名URL

在IIS中,有没有办法定义某种过滤规则来拒绝访问虚拟目录中的文件,除非请求是由某种加密查询字符串“预先签名”的? 还有一种方法可以使请求过期吗? 我无法找到控制这个的方法。

我正在寻找的东西与Amazon S3 Amazon.S3.Model.GetPreSignedUrlRequest.Expires属性提供的内容非常类似,但在IIS中。 以下是Amazon S3示例代码的链接。

期望目标的情景:

请求: http://MyServerName/MyFolderThatIsAddedAsAVirtualDirectoryToDefaultWebsiteInIIS/MyImage.jpg默认情况下应始终导致“拒绝访问”。 但是,将特定查询字符串附加到请求URL应该可以访问该文件。 此外,我需要URL在一段时间后过期,直到提供新的有效查询字符串。

这里需要某种HTTP模块来处理这个问题,因为有一些自定义逻辑可以实现QueryString匹配和到期。

  public class HttpFilterModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += context_BeginRequest; } void context_BeginRequest(object sender, EventArgs e) { var qs = HttpContext.Current.Request.QueryString["SomeKeyToCheck"]; var url = HttpContext.Current.Request.Url; if (MatchesUrl(url)) { if (!IsAuthenticatedByQueryString(qs)) { HttpContext.Current.Response.StatusCode = HttpStatusCode.Unauthorized; HttpContext.Current.Response.End(); } } } private bool IsAuthenticatedByQueryString(string qs) { // implement code here to check qs value // probably against a DB or cache of tokens return true; } private bool MatchesUrl(Uri url) { // implement code here to match the URL, // probably against configuration return true; } }