0

I would like to handle static file web requests through an HttpModule to show the documents in my CMS according to some policies. I can filter out a request, but I don't know how to directly process such a request as asp.net should do.

2
  • an ihttpmodule would require a lot of work. wouldn't standard pages or an mvc framework be better? Commented Mar 22, 2013 at 15:15
  • I've expressed myself badly, I need an httpHandler or an httpModule to handle static file content and allow a registered user to directly access a document. Commented Mar 22, 2013 at 16:03

1 Answer 1

1

Is this what you're looking for? Assuming you're running in integrated pipeline mode, all requests should make it through here, so you can kill the request if unauthorized, or let it through like normal otherwise.

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks for the reply, I solved with a Server.Transfer. I don't understand why the return instruction can't deliver the right static file requested

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.