【发布时间】:2012-01-03 07:24:03
【问题描述】:
我有这个 MVC 应用程序,我在其中声明了以下路由:
routes.RouteExistingFiles = false;
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");
routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css(/.*)?" });
我在 IIS 上部署了我的应用程序,我发现每个静态资源都调用了 Application_BeginRequest
protected void Application_BeginRequest(object sender, EventArgs e)
{
Log.Write("Begin request for " + Request.RawUrl)
}
我尝试以这种方式设置web.Config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<handlers accessPolicy="Read, Execute, Script">
<add name="StaticFiles" path="*.js, *.css, *.jpg, *.jpeg, *.gif, *.png" verb="*" type="StaticFileModule" resourceType="Either" requireAccess="None" preCondition="integratedMode" />
</handlers>
</system.webServer>
不幸的是,没有成功。有人对此有线索吗?
【问题讨论】:
-
你为什么使用
BeginRequest? -
实例化数据库会话。
-
您可以配置 IIS 以便它为静态文件提供服务吗?它不需要实例化 asp.net 进程。
-
@Dallas - StaticFiles 处理程序正在调用 IIS 的 StaticFileModule,但它不起作用。如果你能在哪里找到这个解决方案的例子,我会很高兴:)
标签: asp.net-mvc-3 web-config asp.net-mvc-routing application-lifecycle iis-modules