When moving to MVC, and now IIS7, we started having issues in that our HTTP Module that opens and closes the ISession was called on every request (static files, etc.). I wanted to avoid doing a full rewrite of NH session management, so I implemented this code in my module, to filter out everything but requests going to the mvchandler:
void context_PreRequestHandlerExecute(object sender, System.EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
Type mvcht = typeof(System.Web.Mvc.MvcHandler);
if (context.Handler != null && context.Handler.GetType().IsAssignableFrom(mvcht))
{
// Code Here
}
}
My question is, I have never used this event in the request pipline. So, are there any hidden pitfalls in doing this? Also, am I looking at a performance issue in running this check for every request? I haven't noticed anything yet, but this is a new and still small app.