9

我的 Global.asax (Umbraco 4.7) 中有以下内容

  • 应用程序_开始
  • Application_EndRequest
  • 应用程序错误
  • 会话开始
  • 会话_结束

现在我已经升级到 global.asax 继承自的 Umbraco 6.0.3Umbraco.Web.UmbracoApplication

我在哪里放置我的事件处理程序(以及等效的方法名称是什么)?

4

1 回答 1

18

这是我到目前为止发现的。

您可以创建自己的课程

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)
      {
        // 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
  }
}

并让 Global.asax 从您的班级继承

<%@ Application Codebehind="Global.asax.cs" Inherits="Global" Language="C#" %>

替代方法:继承 ApplicationEventHandler - 但它不适合我

于 2013-04-09T03:47:27.143 回答