Register Event Handler In umbraco

Introduction:

I assume that you have basic idea of event in c#. If not then please have a look Basic Event Handler  As we know that event is mechanism via which we can send notification to a class to perform some task. In umbraco we will use event handler or event concept to achieve following task:

  • Perform certain task before publishing a document.
  • Perform certain task after deleting a node.
  • Perform certain task after package install.
  • Perform certain task after member is created.

So these task we can achieve via use of event handler.

  • How to register event handler in umbraco 4.0 or pre 4.0 version.For accomplishing this task we will use ApplicationBase Class first you have to understand the concept which umbraco use. Every time when you run umbraco application umbraco search whether any class inherit the ApplicationBase class if he find then he understand that some thing is there so travel to your class which inherited ApplicationBase and after that perform your task…. Lets have a look of these code.

using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using umbraco.BusinessLogic;

namespace xForum
 {
 public class publicclassMyUserControl: ApplicationBase
  {
    public MyDefaultEmptyConstructor()
     {
       // Your logic goes here.
       // and this logic will run when umbraco application is started.
     }
  }
 }

How to register event handler in Umbraco 4.1 + version.
In umbraco 4 + version things has been changed and same task can be archived by Inheriting
umbraco.Global namespace. But guys it will not work in 4.8 version because there is no file called Global.asmx.

</pre>
using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using umbraco.BusinessLogic;

namespace xForum
 {
  public class YourAppGlobalPage : umbraco.Global
  {
   protected override void Application_Start(object sender, EventArgs e)
   {
     // Call base class first.
     base.Application_Start(sender, e);

     // After that write your logic here which will execute at the start
     // umbraco application.
   }
  }
 }
<pre>

This is part 1 of Register Event Handler In umbraco I will come with demo in Part 2.

If you have any query regarding this please leave a comment.

Advertisements

3 thoughts on “Register Event Handler In umbraco

  1. Pingback: Umbraco: How to Create Custom data type in umbraco using c#. | [Code Destination]

  2. Pingback: Create your first Rss Feed Burner in umbraco | [Code Destination]

  3. Pingback: Install umbraco manually. | [Code Destination]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s