Saturday, October 29, 2016

Web Activator

Web Activator is useful if you want to hook up your code before to or end of application execution. Logging before and after execution of application might be one scenario where we can use Web Activator.

To use Web Activator we have to get it from NuGet. Just install this package.


Web Activator has 4 flavor to hook custom code in place. In this example we have used PreApplicationStartMethod 


For demonstration. So, the method will execute before anything executes in application. Yes, before Application_Start or execution of App_Code folder’s code. Here is way to hook up code using Web Activator.

[assembly : WebActivatorEx.PreApplicationStartMethod(typeof(Mvc.Models.FirstClass),"FirstMethod")]
namespace Mvc.Models
{
   public class FirstClass
    {
        public static void FirstMethod()
        {
           
        }
    }
}

No comments:

Post a Comment