9

Global.asax(Umbraco 4.7)に次のものがありました

  • Application_Start
  • Application_EndRequest
  • アプリケーションエラー
  • セッション開始
  • Session_End

これで、global.asax が継承する Umbraco 6.0.3 にアップグレードしました。Umbraco.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 に答える