开发者

How to skip static http requests when using one UoW per http request

I am using one NHibernate UoW per http request in my .net mvc 2 web application. I was just wondering how I can skip creating a UoW for 开发者_C百科static http requests like images.


You can convert your unit of work implementation to be an implementation of IActionFilter instead of an HttpModule. So OnActionExecuting you can begin your unit of work and OnActionExecuted you can end the unit of work. Then just apply it to your controllers and actions that do data processing.


you can use the IRequiresSessionState marker interface.

private void BeginTransaction(object sender, EventArgs e)
{
     HttpApplication app = (HttpApplication)source;
     if (app.Context.Handler is IRequiresSessionState) {
        // do work
     }
}

the staticfilehandler does not apply Session to the request.


I'm not sure if the StaticFileHandler actually issues Begin/EndRequest but I'm guessing not. If you notice that it is triggered for your static files, I assume that your order of handlers are wrong or wildcards for handlers are wrong.

If you map "*" to you MVC handler, maybe you might need to actually move your static content into a subfolder and override the web.config and clear all handlers and only add StaticFileHandler on that.

I noticed that you mention that you use a IHttpModule for the UoW, so I'm guessing that you hijack that for every request.

You could do this:

create a subfolder that you call for example "/static/" and move your static files here. In that folder, create a web.config which contains the following:

<handlers>
    <clear />
    <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="Script" />
</handlers>

and remove the UoW module here (maybe you would only need this row)

<modules>
    <remove name="YourUoWModuleName" />
</modules>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜