This article describes how to wrap the Elmah error handler in another event handler that allows access to session state:
http://groups.google.com/group/elmah/msg/a0aa776d348ba97e
In Global.asax, you could then have something like the following:
protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
{
// Get the filename being requested
string filename = Path.GetFileName(Request.Path).ToLower();
// Verify that a user is logged in by checking the session
bool isValid = (HttpContext.Current.Session["User"] != null);
// Throw error if invalid
if (filename == "elmah.axd" && !isValid)
throw new SecurityException("Access to elmah.axd is denied");
}
The standard Elmah handler doesn't implement IRequiresSessionState or IReadOnlySessionState, so you'll have to create another event handler to wrap this, as described in the link mentioned above. Otherwise, you won't be able to access the session in the Application_PreRequestHandlerExecute event.