开发者

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 i开发者_开发知识库s 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


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


I guess that you could put the controller classes in App_Code and be done with it. you will need to map a special extension for Monorail urls. If you do not use SOAP webservices (.asmx) then map this extension to Monorail's HttpHandlerFactory.

An interesting culprit could be that the actual assembly containing the App_code files does not have a nice name (I think), and MonoRail does need to know the assembly from which to locate controller classes.

I'd suggest you play with the hints I've listed above and see where it gets you. Share the exceptions you see and hopefully we'll get to the bottom of it soon

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜