You can create an HttpHandler to substitute for the lack of a Global.asax.cs file. Save the following code as AppEvents.cs in your \web\app_code folder:
Code:
using System;
using System.Web;
using System.Web.SessionState;
public class AppEvents : IHttpModule
{
public AppEvents() {}
static bool firstTime = true;
public void Init(HttpApplication application)
{
SessionStateModule session = application.Modules["Session"] as SessionStateModule;
//application.BeginRequest += new EventHandler(Application_BeginRequest);
//application.AuthenticateRequest += new EventHandler(Application_AuthenticateRequest);
//application.PostAuthenticateRequest += new EventHandler(Application_PostAuthenticateRequest);
//application.AuthorizeRequest += new EventHandler(Application_AuthorizeRequest);
//application.PostAuthorizeRequest += new EventHandler(Application_PostAuthorizeRequest);
//application.ResolveRequestCache += new EventHandler(Application_ResolveRequestCache);
//application.PostResolveRequestCache += new EventHandler(Application_PostResolveRequestCache);
if (session != null)
{
// session.Start += (new EventHandler(Session_Start));
}
//application.AcquireRequestState += new EventHandler(Application_AcquireRequestState);
//application.PostAcquireRequestState += new EventHandler(Application_PostAcquireRequestState);
//application.PreRequestHandlerExecute += new EventHandler(Application_PreRequestHandlerExecute);
//application.PostRequestHandlerExecute += new EventHandler(Application_PostRequestHandlerExecute);
//application.ReleaseRequestState += new EventHandler(Application_ReleaseRequestState);
//application.PostReleaseRequestState += new EventHandler(Application_PostReleaseRequestState);
//application.UpdateRequestCache += new EventHandler(Application_UpdateRequestCache);
//application.PostUpdateRequestCache += new EventHandler(Application_PostUpdateRequestCache);
//application.EndRequest += new EventHandler(Application_EndRequest);
//application.PreSendRequestHeaders += new EventHandler(Application_PreSendRequestHeaders);
//application.PreSendRequestContent += new EventHandler(Application_PreSendRequestContent);
//application.Disposed += new EventHandler(Application_Disposed);
//application.Error += new EventHandler(Application_Error);
if (firstTime)
{
// Application_Start();
firstTime = false;
}
}
public void Dispose() {}
void Application_Start()
{
throw new NotImplementedException();
}
void Application_BeginRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_AuthenticateRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostAuthenticateRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_AuthorizeRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostAuthorizeRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_ResolveRequestCache(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostResolveRequestCache(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Session_Start(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_AcquireRequestState(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostAcquireRequestState(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostRequestHandlerExecute(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_ReleaseRequestState(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostReleaseRequestState(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_UpdateRequestCache(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PostUpdateRequestCache(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_EndRequest(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_PreSendRequestContent(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_Disposed(object sender, EventArgs e)
{
throw new NotImplementedException();
}
void Application_Error(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
Step 1; I have all of the event handler registrations commented-out. If you want to handle one of the events, simply uncomment that handler registration, then add your code to the corresponding handler method.
Step 2; let your website know about the module by adding an entry into the < httpModules > section of web.config:
Code:
< add name="AppEvents" type="AppEvents, App_code" />
This technique behaves exactly like the events inside Global.asax.cs.