ASP.NET HttpModule请求处理

我想通过HttpModule处理静态文件Web请求,以根据某些策略在CMS中显示文档。 我可以过滤出一个请求,但我不知道如何直接处理这样的请求,因为asp.net应该这样做。


这是你在找什么? 假设你在集成管道模式下运行,所有请求都应该在这里完成,所以如果未经授权,你可以终止该请求,否则就像平常一样让它通过。

public class MyModule1 : IHttpModule
{
    public void Dispose() {}

    public void Init(HttpApplication context)
    {
        context.AuthorizeRequest += context_AuthorizeRequest;
    }

    void context_AuthorizeRequest(object sender, EventArgs e)
    {
        var app = (HttpApplication)sender;

        // Whatever you want to test to see if they are allowed
        // to access this file. I believe the `User` property is
        // populated by this point.
        if (app.Context.Request.QueryString["allow"] == "1")
        {
            return;
        }

        app.Context.Response.StatusCode = 401;
        app.Context.Response.End();
    }
}

<configuration>
  <system.web>
    <httpModules>
      <add name="CustomSecurityModule" type="MyModule1"/>
    </httpModules>
  </system.web>
</configuration>
链接地址: http://www.djcxy.com/p/43799.html

上一篇: ASP.NET HttpModule Request handling

下一篇: Limiting HttpModule to only process certain requests