default, the class isn’t compiled until runtime (as is the case for any class in the code direc-
tory). The type will still show up via IntelliSense in the IDE, and you can still code against it in
a strongly typed manner.
To trap HttpApplicaiton events, you now have two options. The aforementioned naming
convention will work. Or you can add delegates to the base class events from the constructor.
The following class traps both the BeginRequestand PreRequestHandlerExecuteevents: one by
explicitly creating the trap; the other by using the naming convention. It also declares a static
field that will be available throughout the application:
using System;
using System.Web;
public class MyImpl : HttpApplication
{
public static string SomeStaic = "This is a static variable";
public MyImpl()
{
this.PreRequestHandlerExecute += new
EventHandler(MyImpl_PreRequestHandlerExecute);
}
void Application_OnBeginRequest(object sender, EventArgs e)
{
Response.Write("Entering BeginRequest
");
}
void MyImpl_PreRequestHandlerExecute(object sender, EventArgs e)
{
Response.Write("Entering PreRequestHandlerExecute
");
}
}
using System.Web;
public class MyImpl : HttpApplication
{
public static string SomeStaic = "This is a static variable";
public MyImpl()
{
this.PreRequestHandlerExecute += new
EventHandler(MyImpl_PreRequestHandlerExecute);
}
void Application_OnBeginRequest(object sender, EventArgs e)
{
Response.Write("Entering BeginRequest
");
}
void MyImpl_PreRequestHandlerExecute(object sender, EventArgs e)
{
Response.Write("Entering PreRequestHandlerExecute
");
}
}
No comments:
Post a Comment