MonoRail Root Directory Routing + RoutingModuleEx

This crap is so under-documented. It took me forever to figure it out.

I love the CastleProject. But damn… documentation… the hell?

If you want http://www.yourdomain.com/ to default to say “/Home/Index.castle”, then this is how I did it. I had to use both routing engines in MonoRail (Eww, people!  Seriously. Gross!) because I could not figure out how to do it with just the new one (RoutingModuleEx).

Add this to your web.config to the top of  your httpModules section. I don’t know if it has to be on top, but it worked for me, so don’t touch it!

<httpModules>
  <!-- Need routing.old for Root Routing. -->
  <add name="routing.old"
       type="Castle.MonoRail.Framework.RoutingModule, Castle.MonoRail.Framework" />
  <add name="routing"
       type="Castle.MonoRail.Framework.Routing.RoutingModuleEx, Castle.MonoRail.Framework" />

Then, in your MonoRail web.config block, add:

<monorail>
<routing>
  <rule>
    <pattern>^(/default.aspx)(.)*$</pattern>
    <replace><![CDATA[/home/index.castle]]></replace>
  </rule>
</routing>

That should work.  If it doesn’t, well damn. I might be able to help, but the Castle Project Users Group is probably way more qualified.

Note that this adds both routing engines. The new one (RoutingModuleEx) let’s you do sexy routes like so:

var engine = RoutingModuleEx.Engine;
engine.Add(new PatternRoute("/Login")
               .DefaultForController().Is("Login")
               .DefaultForAction().Is("Login"));

I think this may be one of the few resources detailing how it works: Hammet’s RoutingModuleEx Blog Post.

This is how we roll.

Comments (3) left to “MonoRail Root Directory Routing + RoutingModuleEx”

  1. Ben Scheirman wrote:

    Why not contribute some (even minor) documentation to the site? Documentation is almost always severely lacking in most open source projects, and Castle is HUGE. Having full comprehensive docs is up to the users.

  2. James Thigpen wrote:

    I would, and I’ve looked into this, but it’s kind of a PITA.

    Castle docs are written in Castle Anakia, a port of some Apache project also called Anakia. The docs are written in a very html-ish xml format that Castle Anakia builds using some kind of nant task. There is a stepsheet on the castle site for doing it. It looks really annoying. Then after I write crazy xml docs and build them with nant commands and check them I have to submit a patch to the mailing list.

    It’s sort of like they’ve never heard of a Wiki.

    It’s sort of that “Pit of Success” thing. The barrier to entry for a casual contribution to their documentation is pretty high.

    My solution: I’m writing these blog posts. Maybe someone will google and find them. I know I google first before I consult the castle docs, I imagine other people do, too.

    Update: Yes I do know there is a castle wiki, but I’ve never found it to actually be useful, and it’s really badly organized. So yeah.

    Update Update: This shouldn’t be interpreted to read that I don’t think the Castle Project is pretty much pure awesome. It’s just that the documentation sucks. The fact that I still use it and love it in spite of this should be an indicator of how awesome it really is.

  3. Ken Egozi wrote:

    @James:
    the old wiki was not very fun, agree.
    However, there’s using.castleproject.org website, which is the exact place as to where this kind of a use case should go to.
    so please check this site out, and put that knowledge in there, or at least a link to this post

Post a Comment

*Required
*Required (Never published)