【发布时间】:2015-06-28 05:07:55
【问题描述】:
我正在使用 umbraco 7.0,我需要在应用程序启动、会话开始和会话结束时添加一些自定义代码。至于在 umbraco 中注册事件,我们必须从 Umbraco.Core.ApplicationEventHandler 继承,我是这样的。但我们只能覆盖ApplicationStarted,而不是像我们在 Global.asax 中所做的那样与 Session 相关。
我见过Global.asax in Umbraco 6,但我无法访问会话,如该答案if (Session != null && Session.IsNewSession) 所示,可能是umbraco 6,而umbraco 7 发生了一些变化。
有什么解决办法吗?
这是上述帖子中建议的代码。
public class Global : Umbraco.Web.UmbracoApplication
{
public void Init(HttpApplication application)
{
application.PreRequestHandlerExecute += new EventHandler(application_PreRequestHandlerExecute);
application.EndRequest += (new EventHandler(this.Application_EndRequest));
//application.Error += new EventHandler(Application_Error); // Overriding this below
}
protected override void OnApplicationStarted(object sender, EventArgs e)
{
base.OnApplicationStarted(sender, e);
// Your code here
}
private void application_PreRequestHandlerExecute(object sender, EventArgs e)
{
try
{
if (Session != null && Session.IsNewSession) // Not working for me
{
// Your code here
}
}
catch(Exception ex) { }
}
private void Application_BeginRequest(object sender, EventArgs e)
{
try { UmbracoFunctions.RenderCustomTree(typeof(CustomTree_Manage), "manage"); }
catch { }
}
private void Application_EndRequest(object sender, EventArgs e)
{
// Your code here
}
protected new void Application_Error(object sender, EventArgs e)
{
// Your error handling here
}
}
【问题讨论】:
标签: asp.net-mvc global-asax umbraco7