2

I have a third party custom authentication HTTP module. I would like this module to configured to particular action method of a controller. Is this possible?

I know we can configure at folder level by having appropriate web.config at folder level, but I am looking for particular action method of particular controller.

0

3 Answers 3

4

You can't enable a Http module to a particular controller, but you can enable it to a particular request path in web.config. That effectively does the job imo. The following web.config snippet enables "ThirdParty.HttpModule" only for request that match the "yourController" path. This should work with MVC, WebForms, and generic handlers as well.

<location path="yourController" inheritInChildApplications="false">
  <system.web>
    <httpModules>
      <add name="yourModule" type="ThirdParty.HttpModule"/>
    </httpModules>
  </system.web>
</location>

The inheritInChildApplications part is important, if you have any other applications in subdirectories of this application, because child applications would inherit this configuration by default, and you may not want this module to work in child applications.

More info on MSDN.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that the VS development server does not use http modules; you'll have to switch to IIS Express for development.
0

I believe you're looking for action filters. There are numerous samples available on the web demonstrating how to set them up.

http://msdn.microsoft.com/en-us/library/dd381609%28v=VS.98%29.aspx

2 Comments

Im not looking action filters. As I said in the question I have to use third party developed custom HTTP module.
I do not believe that's possible. Action filters are the only way to do what you're wanting to achieve in MVC.
0

You should use ActionFilters for that. If you really want to use a HttpModule, then the module has to check if it should execute its logic based on the URL. The HttpModule does not know anything about your controllers and vice versa.

2 Comments

As I mentioned in question, I have to use third party custom HTTP module. I do not have control on that.
Then another possibility would be, to wrap it into another HttpModule that only gets executed if a certain URL is 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.