IIS Virtual Directory Get Pre Signed URL with Expiration

戏子无情 提交于 2019-12-03 23:10:26

You will need some sort of HTTP Module here to deal with this as there is custom logic to implement for QueryString matching and expiration.

  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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!