我读到umbraco在应用程序启动时运行我的代码我需要继承umbraco.Global并覆盖Application_Start.我已经完成了以下简单的代码,它位于umbraco网站项目引用的自己的程序集中,并在它的bin文件夹中.
public class AtomicF1Global : umbraco.Global
{
protected override void Application_Start(object sender, EventArgs e)
{
base.Application_Start(sender, e);
new WindsorStarter().Start();
throw new Exception("Reached Custom Global");
}
}
Run Code Online (Sandbox Code Playgroud)
唯一的例外是在那里纯粹向我证明它没有被召唤.
据我所知,我所要做的就是我所做的一切.我不需要在任何地方更新umbraco表(就像对umbraco进行许多不同的修改一样).
但是,我的代码永远不会被调用,我也无法找到原因.我需要在某处注册吗?
我还检查过以确保bin目录中没有"App_Global.asax.dll".
我也尝试在umbraco站点项目中创建一个Global.asax,如下所示:
<%@ Application Language="C#" Inherits="umbraco.Global" %>
<%@ Import Namespace="atomicf1.domain" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Call Global base class first
base.Application_Start(sender, e);
// Code that runs on application startup
new WindsorStarter().Start();
throw new Exception("Reached Custom Global");
}
</script>
Run Code Online (Sandbox Code Playgroud)
umbraco的版本是4.7.1(.NET 4.0).
如果您希望代码在应用程序启动时运行,通常的方法是创建一个继承自 ApplicationBase 的类。当 Umbraco 应用程序启动时,会调用继承于此的公共类。以下是我们在 Umbraco 网站之一上使用的启动事件之一的一些示例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;
using umbraco.BasePages;
namespace MySite.Events
{
public class EventHandlers : ApplicationBase
{
public EventHandlers()
{
//put your code to run on app startup here
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9185 次 |
| 最近记录: |