火灾的BeginRequest在ASP.NET MVC应用程序的静态文件 [英] BeginRequest fires for static files in ASP.NET MVC app

查看:213
本文介绍了火灾的BeginRequest在ASP.NET MVC应用程序的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IM pression下的静态文件(CSS,图片,@字体面文件等)绕过ASP.NET完全,并分别由IIS直接服务。

I was under the impression that static files (CSS, images, @font-face files, etc) bypassed ASP.NET completely, and were served directly by IIS.

不过,我BeginRequest事件处理函数被调用每一个HTTP请求,包括那些静态文件。这涉及到我,因为我创建一个实体框架数据上下文用于该事件处理程序的每个请求的生命周期。我不希望创建这些方面,如果他们永远不会被使用。

However, my BeginRequest event handler is being called for every HTTP request, including those for static files. This concerns me because I'm creating an Entity Framework data context to be used for the lifetime of each request in that event handler. I don't want to create those contexts if they're never going to be used.

我在Windows 7旗舰版使用IIS 7中没有定义特殊的处理程序映射。我有错了?如果这些事件会触发?

I'm using IIS 7 on Windows 7 Ultimate with no special handler mappings defined. Do I have it wrong? Should these events be firing?

推荐答案

我相信一个默认的ASP.NET MVC网站有这一套在web.config中。

I believe a default ASP.NET MVC site has this set in the web.config.

<modules runAllManagedModulesForAllRequests="true" />  

这意味着每个.NET模块将被加载每个IIS请求。这是ASP.NET MVC的处理无扩展名的路由必需的。它本质上是一个通配符映射,你会在IIS中,将匹配一切,这路线ASP.NET生活在web.config中写

This means every .NET module will be loaded for every IIS request. This is required for ASP.NET MVC to handle extension-less routing. It's essentially a wildcard mapping that you would write in IIS that would match everything and route it to ASP.NET that lives in the web.config.

阅读更多<一个href=\"http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx\">here,包括一个方式,如果你不使用.NET 4.0禁止的行为。这是讨厌的,但它是不能用具有由asp.net提供静态文件的开销处理站点干净的解决方案。

Read more here, including a way to disable the behavior if you aren't using .NET 4.0. It is nasty, but it's the cleanest solution for sites that can't deal with the overhead of having static files served by asp.net.

这篇关于火灾的BeginRequest在ASP.NET MVC应用程序的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆