void context_BeginRequest(object sender, EventArgs e)
{
try
{
// Restore session state if this is the first request
if (!sessionRestored)
{
lock (stateFileMutex)
{
if (!sessionRestored)
{
stateFile = Path.Combine(HttpContext.Current.Server.MapPath("~/"), Settings.Current.StateFile);
RestoreSessionState();
sessionRestored = true;
}
}
}
// make sure application requests do not get through if an unexpected transaction abort occurs
if (Session.IsRollbackPending && !(HttpContext.Current.Request.Url.ToString().ToLower().Contains(Settings.Current.HandlerPath.ToLower()) ))
throw new ApplicationException("Transaction was aborted and is awaiting rollback");
Session.Tracker.StartActivity();
// If a previous module aborts the request, begin request never runs
HttpContext.Current.Items[REQUEST_STARTED] = true;
}
catch(Exception err)
{
HttpContext.Current.Items[REQUEST_ABORTED] = true;
HttpContext.Current.Response.StatusCode = 503; // service unavailable
HttpContext.Current.Response.Write("Amnesia is currently blocking requests. " + err.Message);
HttpContext.Current.Response.End();
return;
}
}