Search code examples
asp.netcastle-monorail

Castle Monorail in Asp.NET web site?


In our system most of the code is in an asp.net (2.0) web site, I discovered Castle Monorail a few month ago and I think it's really easier to use than asp.net / webforms.

Here is what we need : - Use Castle Monorail - Our code must be in the website (my chief is a kind of old school web developer so he prefer to have some ".cs" files than one ".dll"). - We have to keep the existing webforms code

So maybe if you have a tutorial or something like that (I found a lot of tutorial about asp.net MVC and castle monorail but I did find any with asp.net 2.0)/

Merci les collegues


Solution

  • So it was pretty simple (15 min top) :

    1/ Get the element that you need from web.config : - config section handler

    <section name="monorail" type="Castle.MonoRail.Framework.Configuration.MonoRailSectionHandler, Castle.MonoRail.Framework" />
    

    -Configuration itself

      <monorail>
        <controllers>
          <assembly>App_Code</assembly>
          <assembly>Castle.Monorail.ViewComponents</assembly>
    
        </controllers>
        <viewEngines viewPathRoot="Views">
          <add type="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity" />
        </viewEngines>
      </monorail>
    

    "App_Code" is the name of the web site assembly.

    -http handlers

    <add verb="*" path="*.rails" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework" />
          <!--block direct user access to template files-->
          <add verb="*" path="*.vm" type="System.Web.HttpForbiddenHandler" />
          <add verb="*" path="*.boo" type="System.Web.HttpForbiddenHandler" />
          <add verb="*" path="*.st" type="System.Web.HttpForbiddenHandler" />
    

    -http modules

    <add name="monorail" type="Castle.MonoRail.Framework.EngineContextModule, Castle.MonoRail.Framework" />
    

    2/ Take the dll that you need, in my case (I don't use activerecord) :

    Castle.Components.Binder.dll

    Castle.Components.Common.EmailSender.dll

    Castle.Components.Common.TemplateEngine.dll

    Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.dll

    Castle.Components.Validator.dll

    Castle.Core.dll

    Castle.MonoRail.Framework.dll

    Castle.MonoRail.Framework.Views.NVelocity.dll

    Castle.MonoRail.ViewComponents.dll

    3/ Add a class in your App_Code folder (for instance TestMonorailController) :

    using Castle.MonoRail.Framework;

    public class TestMonorailController : SmartDispatcherController
    {
        public TestMonorailController()
        {
    
        }
        public void OnePage()
        {
            PropertyBag["toto"] = "TEST";
        }
    }
    

    4/ Add a Views folder in the root of your website 5/ Add a TestMonorail folder in the folder you just created 6/ Add a file name "OnePage.vm" in this folder :

    $toto
    

    7/ Test your website :

    http://localhost:XX/YourWebSite/TestMonorail/OnePage.rails

    and you should see

    "TEST"

    Et voila :) I can edit my production code. Thx Ken