Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
MonoRail on IIS7 Redux : Configuration And Routing

A while ago I posted on the very basics about using Monorail on IIS7. Implementing the routing module requires a bit more tuning though so I wanted to quickly post my configuration and some things to look for if you are having difficulty getting routing going on Monorail. This is mostly to help those googling and to put all this stuff in one place.

First, the configuration which Adam Tybor was gracious enough to help me with:

<configuration>
<!--...-->
<system.webServer>
        <modules>
            <add name="routingEx" type="Castle.MonoRail.Framework.Routing.RoutingModuleEx,Castle.MonoRail.Framework" preCondition="managedHandler" />
            <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule,Castle.MicroKernel" preCondition="managedHandler" />            
        </modules>
        <handlers accessPolicy="Script, Execute, Read">
            <clear />
            <add name="ASPX" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" />            
            <add name="Block-Boo" path="*.boo" verb="*" type="System.Web.HttpForbiddenHandler, System.Web" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
            <add name="Block-Brail-JS" path="*.brailjs" verb="*" type="System.Web.HttpForbiddenHandler, System.Web" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
            <add name="Block-Brail" path="*.brail" verb="*" type="System.Web.HttpForbiddenHandler, System.Web" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv2.0" />
            <add name="Monorail-All" path="*" verb="*" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" preCondition="" />
            
            
        </handlers>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
</configuration>

 

If the 'system.webServer' node doesn't look familiar to you, go read the previous post to get up to speed on how IIS7 looks at your config files.

It is important to note that this configuration <clear/>s all the handler mappings from IIS7 and only implements what is required. Not doing so will prevent the routing module from doing it magic...I am still not sure why even after removing my StaticFile handler I was unable to get my routing module to work, but I looked through all the IIS7 trace logs and it appeared one of the many modules mapped by default was preventing RoutingEx from handling the request.

Another important thing to note is that this configuration would pass all requests through the monorail module which obviously will be less-than-optimal for static content. You can read more about implementing a best practice to handle this here .  Basically, you are just setting up another website with stripped down handler mappings either on IIS or some faster server to deliver static content. I have loved separating this kind of stuff out of my web projects as it lets me centralize all the common scripts/images AND speed up my sites.

A minor note, too, is that I am passing *.aspx calls to the PageHandlerFactory. This is simply to use some server controls on an aspx page or two I need to use that require normal webforms handling (with ViewState darkness and Event Model Labyrinths ). I'll be posting more on that setup later...

Other Resources:


Posted 04-02-2008 11:25 PM by Michael Nichols

[Advertisement]

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)