的Global.asax在一把umbraco 6

问题描述:

我在我的Global.asax(一把umbraco 4.7)的Global.asax在一把umbraco 6

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

现在我已升级到Umbraco 6.0.3,其中global.asa x继承自Umbraco.Web.UmbracoApplication

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

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

您可以创建自己的类

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 - 但它不是为我工作

+0

非常感谢你许多! – nrodic 2013-05-23 11:59:59

+0

您能否更新我在umbraco中保存全局类的位置,并且此类名是Global.cs还是Global.asax.cs?我知道,这很奇怪,但它不适合我,可能是我错过了一些东西。 – 2013-07-04 08:11:40

+1

Mine是App_Code/Global.cs,但我不认为文件名很重要 – Aximili 2013-07-10 05:10:39