Umbraco的Global.asax 6

时间:2013-04-08 06:39:01

标签: umbraco global-asax

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

  • 的Application_Start
  • Application_EndRequest
  • 的Application_Error
  • 在session_start
  • Session_End中

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

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

1 个答案:

答案 0 :(得分: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#" %>

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