0

我有这样的MVC应用程序,我声明如下路线:应用程序调用Begin_Request图片,CSS和JS ASP.NET MVC 3

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> 

不幸的是,没有成功。任何人都有这方面的线索?

+0

你为什么使用'BeginRequest'? – SLaks

+0

实例化数据库会话。 – abx78

+0

你可以配置IIS以便它提供静态文件吗?它不需要实例化一个asp.net进程。 – Dallas

回答

1

Application_BeginRequest与路由无关。
它将始终为所有托管请求启动。

如果您只想处理MVC请求,请使用全局操作筛选器。

+0

你说:不要使用Begin_Request,而是使用全局行为过滤器? – abx78

+0

是的。或者,更好的是,在第一次使用时懒惰地实例化它。或者使用非全局过滤器并将该过滤器应用于需要该数据库的每个操作。 – SLaks