应用程序调用 Begin_Request 获取图像、css 和 js ASP.NET MVC 3
我有一个 MVC 应用程序,其中声明了以下路由:
routes.RouteExistingFiles = false;
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");
routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css(/.*)?" });
每个静态资源也调用了 Application_BeginRequest
protected void Application_BeginRequest(object sender, EventArgs e)
{
Log.Write("Begin request for " + Request.RawUrl)
}
我在 IIS 上部署了我的应用程序,并且我发现对于我尝试设置 web.Config< 的 /code> 以这种方式:
<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>
不幸的是,没有成功。有人对此有线索吗?
I have this MVC application where I declare the following routings:
routes.RouteExistingFiles = false;
routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");
routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });
routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css(/.*)?" });
I deployed my application on IIS and I see that the Application_BeginRequest
is called also for every static resource
protected void Application_BeginRequest(object sender, EventArgs e)
{
Log.Write("Begin request for " + Request.RawUrl)
}
I tried to set the web.Config
in this way:
<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>
No success, unfortunately. Anyone has a clue for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Application_BeginRequest与路由无关。
它将始终触发所有托管请求。
如果您只想处理 MVC 请求,请使用全局操作过滤器。
Application_BeginRequest has nothing to do with routing.
It will always fire for all managed requests.
If you only want to handle MVC requests, use a global action filter.