views:

38

answers:

2

I have an httpModule which has to run before an ActionMethod. I dont want that it is executed when a request for an image comes in.

For some reasons I realy need an HttpModule and cant use an ActionFilter

What is the way to do this?

public class PostAuthenticateModule : IHttpModule
{

        public void Init(HttpApplication app)
        {
           app.PostAuthenticateRequest += new EventHandler(this.OnEnter);
        }

        private void OnEnter(object source, EventArgs eventArgs)
        {

        }

        private static void Initialize()
        {

        }
        public void Dispose()
        {
        }


}

web.config

<httpModules>
  <add type="PostAuthenticateModule.PostAuthenticateModule , PostAuthenticateModule" name="PostAuthenticateModule"/>
</httpModules>
A: 

Just inspect the request and short circuit out of the module's execution if it's a static content type. You can't conditionally add a module to the pipeline for some content types.

Joel Martinez
+1  A: 

If you're using IIS7, have a look at HttpModule Preconditions. Sounds like you want preCondition="managedHandler".

E.g. It could look something like this:

<system.webServer>
  <modules>
    <remove name="PostAuthenticateModule" />
    <add type="PostAuthenticateModule.PostAuthenticateModule , PostAuthenticateModule" name="PostAuthenticateModule" preCondition="managedHandler" />
  </modules>
</system.webServer>

HTHs,
Charles

Charlino