Umbraco 6中的Global.asax [英] Global.asax in Umbraco 6

查看:84
本文介绍了Umbraco 6中的Global.asax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had the following in my Global.asax (Umbraco 4.7)

  • Application_Start
  • Application_EndRequest
  • Application_Error
  • Session_Start
  • Session_End

现在我已经升级到Umbraco 6.0.3,它是global.asax从Umbraco.Web.UmbracoApplication

Now I have upgraded to Umbraco 6.0.3, which global.asax inherits from Umbraco.Web.UmbracoApplication

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

Where do I put my event handlers (and what are the equivalent method names)?

推荐答案

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

This is what I found so far.

您可以创建自己的课程

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从您的类继承

And have Global.asax inherit from your class

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

替代方法:继承ApplicationEventHandler -但这对我不起作用

Alternative method: Inherit ApplicationEventHandler - but it's not working for me

这篇关于Umbraco 6中的Global.asax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆