开发者

ASP.Net MVC Nhibernate Session

开发者 https://www.devze.com 2023-01-10 07:01 出处:网络
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 r

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 ru开发者_开发技巧nning this check for every request? I haven't noticed anything yet, but this is a new and still small app.


Although this doesn't specifically address your question, it should be noted that the cost of opening a session is very minimal. So you may consider not even performing this check in the first place.

0

精彩评论

暂无评论...
验证码 换一张
取 消