0

我有这个 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>

没有成功,很遗憾。有人对此有线索吗?

4

1 回答 1

1

Application_BeginRequest 与路由无关。
对于所有托管请求,它将始终触发。

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

于 2011-11-21T20:11:36.333 回答