Including a HttpModule with a custom Orchard Module

Topics: Customizing Orchard, Writing modules
Nov 30, 2011 at 6:01 AM

I am creating a custom Orchard module that is making use of a custom ASP.NET HttpModule.  I am stuck with trying to get the HttpModule wired up.  If I add it to the main Web.config in the Orchard.Web project it works but when I try and add it to the Web.config in my custom Orchard module's Web.config it never runs.  I believe that adding it to the module's web.config is doing nothing.

What is the recommended way to wire this sort of thing?

Here is section from the custom Orchard Module's web.config

 <system.webServer>
      <modules >
          <remove name="CustomerID" />
          <add name="CustomerID" type="Orchard.Web.CustomerIDHTTPModule"/>
      </modules>
  </system.webServer>

 

Thanks

Coordinator
Nov 30, 2011 at 6:12 AM

The recommended way is not to use a module. Alternatives include custom routes and filters. Why do you need one?

Dec 7, 2011 at 9:48 AM

I also want to this because i have build a imageresizer module but it's basically a proxy/wrapper for the dotNetImageResizer module.

See the discussion about this on: http://orchard.codeplex.com/discussions/279274

and project http://orchardimageresizer.codeplex.com

can you tell me something like this is possible : http://stackoverflow.com/questions/239802/programmatically-register-httpmodules-at-runtime

i tried it but didn't succeeded :( many thanks!

Dec 7, 2011 at 2:26 PM

The probem with this in Orchard is that you have multi-tenancy. And I have a strong suspicion (although I don't know the IIS / HttpModule pipeline deep enough) that you'd end up with a single module instance across all tenants, and this could even cause incompatibilities with some modules if they're not expecting that kind of setup. I very much doubt there's any way to "sandbox" a HttpModule, it's too much a core part of IIS.

The big issue with this is you can't configure things separately from one instance to another. Say you have one tenant that wants a watermark on their images with their company name; when you configure the ImageResizing plugins you'll find all tenants have the watermarks, just as an example. Maybe you could solve this with some cunning rewrites. But that'll make the whole thing much more complex. You could also get "bleed" between tenants, i.e. one tenant can suddenly access the images of another.

I think I mentioned before, I was in discussion with Nathaniel (the creator of ImageResizing.net) about this. He's trying to open out more of the functionality so it can be accessed thru the API, but some parts are impossible. However, I think some of those features can be replicated on Orchard side, and some of them would even be useful in a broader sense than just images. But I haven't looked back into it for a while, because right now I have a solution that works for what I need.

Feb 22, 2012 at 5:26 AM

Actually, you could subclass the ImageResizer's HttpModule class quite easily, and override the .conf property. That would allow you to select the appropriate configuration based on the active tenant. 

Which parts are impossible?