Requests for static files are hitting the managed code in ASP.NET MVC3

谁说胖子不能爱 提交于 2019-11-30 12:53:52

I my machine, the adding of that module is in the root web.config, and it has already an empty preCondition

Perfect. That means this module will always run which is required for MVC as it uses extensionless urls.

So now I am a little bit confused, what is the status of this parameter? Should I use it or shouldn't? why does it come as "true" by default?

Because extensionless url support is new in IIS7 SP1 and IIS7.5 SP1. It is available for IIS7 as a patch that you have to request and install. You will find it here with complete answers to your questions: http://support.microsoft.com/kb/980368

Why this parameter comes to true by default ? Because VS2010 was shipped before IIS7 SP1. Maybe it is at false in new MVC projects in VS2010SP1 ?

Answering your first question about the fact that IIS should bypass ASP.NET for static content.

If configured in integrated mode, IIS 7.5, will allow managed modules to register for events related to requests that are not traditionally handled by ASP.NET, like static files.

This does not happen in IIS 7.5 classic mode, which is similar to IIS 6 and does not allow for a managed module to listen for events in requests that are not handled by ASP.NET.

So, basically if you have runAllManagedModulesForAllRequests="true" with integrated mode, than your managed module will be notified of events for every request. Also, from the documentation on runAllManagedModulesForAllRequests:

True if all managed modules can process all requests, even if the request was not for managed content; otherwise, false.

The default value is false.

The documentation does not explain how this attribute interacts with the preCondition option. From what you experienced it seems to override the preCondition configuration, so I if were you I would leave it at false and just work with the preCondition options even if it means altering other modules preconditions to an empty string to workaround the change of runAllManagedModulesForAllRequests to false.


Update: Found some documentation on the implications of the use of runAllManagedModulesForAllRequests and as already stated, if true, is an override for the preCondition with a managedHandler option.

You can also use a shortcut to enable all managed (ASP.NET) modules to run for all requests in your application, regardless of the "managedHandler" precondition. To enable all managed modules to run for all requests without configuring each module entry to remove the "managedHandler" precondition, use the runAllManagedModulesForAllRequests property in the section:

When you use this property, the "managedHandler" precondition has no effect and all managed modules run for all requests.

You can write the following code for it.

routes.IgnoreRoute("{*allcss}", new { allaspx = @".*\.css(/.*)?" });
routes.IgnoreRoute("{*alljs}", new { allaspx = @".*\.js(/.*)?" });

Please find more information on the below link

http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx

I suppose, if you really wish to ignore, you should not use curved brackets:

routes.IgnoreRoute("Content/{*pathInfo}");
routes.IgnoreRoute("Scripts/{*pathInfo}");

Try this to ignore list of all static files

routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(js|css|gif|jpg|png)(/.*)?" });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!