How to register a IHttpModule in Orchard which has access to the DefaultContentManager (or the equivalent)

Topics: Customizing Orchard, General, Writing modules
Jul 28, 2011 at 3:30 PM

I have been trying to write something for orchard which will check all requests for "_escaped_fragment_" signifying a google ajax crawling request and will perform a 301 redirect to the correct resource which needs to be looked up using the DefaultContentManager.

I had done something like this in a previous project by extending IHttpModule and registering it using

<httpModules>
<add name="GoogleRedirect" type="MyNameSpace.GoogleRedirect"/>
</httpModules>

but have found that using the same approach I can't get access to the orchard content manager.

ie. the following doesn't work

_contentManager = DependencyResolver.Current.GetService<IContentManager>();

I also noticed that Orchard uses Autofac and have been trying to get a line similar to ContainerBuilder().Build().Resolve<IContentManager>() working but the ContainerBuilder doesn't seem to be exposed anywhere?

Is there any way of accessing the DefaultContentManager without having to rewrite the code I currenty have? If not is there a special Orchard way of doing this? What is the easiest way to do it and are there any guides to doing anything similar / any bits of code I can examine? I have been reading through the documentation but not sure of the best way of doing it?

Will carry on reading anyway any help appreciated.

Coordinator
Jul 29, 2011 at 1:20 AM

I answered your other post I believe. It would help if you could link to it from here, to minimize the harm of cross-posting.