Asp.NET 网站中的 Castle Monorail?

发布于 2024-09-06 16:26:37 字数 321 浏览 4 评论 0原文

在我们的系统中,大部分代码都在 asp.net (2.0) 网站中,几个月前我发现了 Castle Monorail,我认为它确实比 asp.net / webforms 更容易使用。

这是我们需要的: - 使用城堡单轨列车 - 我们的代码必须在网站中(我的主管是一位老派的网络开发人员,所以他更喜欢一些“.cs”文件而不是一个“.dll”)。 - 我们必须保留现有的 webforms 代码

所以也许如果您有教程或类似的东西(我找到了很多关于 asp.net MVC 和 castle monorail 的教程,但我确实找到了有关 asp.net 2.0 的教程)/

谢谢同事

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我鬧 2024-09-13 16:26:37

所以这非常简单(顶部 15 分钟):

1/ 从 web.config 获取您需要的元素:
- 配置部分处理程序

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

- 配置本身

  <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”是网站程序集的名称。

-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 module

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

2/ 在我的例子中获取您需要的dll(我不使用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/ 在 App_Code 文件夹中添加一个类(例如 TestMonorailController):

使用 Castle.MonoRail.Framework;

public class TestMonorailController : SmartDispatcherController
{
    public TestMonorailController()
    {

    }
    public void OnePage()
    {
        PropertyBag["toto"] = "TEST";
    }
}

4/ 在网站根目录中添加 Views 文件夹
5/ 在刚刚创建的文件夹中添加一个TestMonorail文件夹
6/ 在此文件夹中添加文件名“OnePage.vm”:

$toto

7/ 测试您的网站:

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

并且您应该看到

“TEST”

等瞧:)我可以编辑我的生产代码。谢谢肯

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

野鹿林 2024-09-13 16:26:37

我想您可以将控制器类放入 App_Code 中并完成它。
您需要为单轨铁路网址映射一个特殊的扩展名。
如果您不使用 SOAP Web 服务 (.asmx),则将此扩展映射到 Monorail 的 HttpHandlerFactory。

一个有趣的罪魁祸首可能是包含 App_code 文件的实际程序集没有一个好的名称(我认为),并且 MonoRail 确实需要知道从中查找控制器类的程序集。

我建议您尝试一下我上面列出的提示,看看它会给您带来什么。分享您看到的异常情况,希望我们能尽快查清真相

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文