<modules runAllManagedModulesForAllRequests="true">. In fact this is quite a drastic thing to do to solve the routing problem and has global effects that could CAUSE ERRORS.You need a module that goes by the name of UrlRoutingModule-4.0 to be running through IIS. Now, since your MVC URLs are likely to end without .aspx these will not be picked up by IIS and run through the intergrated pipeline and therefore you will end up with 404 not found errors. I struggled with this when I was getting started until I found the
<modules runAllManagedModulesForAllRequests="true"> workaround.This highly recommended fix can cause other problems. These problems come in the form of making all your registered HTTP modules run on every request, not just managed requests (e.g. .aspx). This means modules will run on ever .jpg .gif .css .html .pdf etc.
This is:
- a waste of resources if this wasn't the intended use of your other modules
- a potential for errors from new unexpected behaviour.
Better solution
Fine, so the ranting about<modules runAllManagedModulesForAllRequests="true"> is over. What is a better solution?In the modules section of your web.config, you can add the UrlRoutingModule-4.0 module in with a blank precondition meaning it will run on all requests. You will probably need to remove it first since it is most likely already registered at machine level. So make your web.config look like this:
<modules> <remove name="UrlRoutingModule-4.0" /> <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" /> <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. --> </modules>
Note: the modules element does NOT contain the runAllManagedModulesForAllRequests="true" attribute because it is evil!



Thank you! I've been fighting this issue for several days, and now have it working correctly.
ReplyDeleteeven better solution
ReplyDeletehttp://support.microsoft.com/kb/980368
that worked for me! need to sing that link out from the rooftops, have been pulling my hair out for hours
DeleteSame here. No need to specify modules manually if you install the hotfix.
DeleteHi!
ReplyDeleteRemoving the runAllManagedModulesForAllRequests="true" flag or setting it to false has one pitfall: Some of the global.asax event handlers stop working for MVC requests.
With your configuration in a new MVC application project Application_Start and Application_End events are no problem, but Application_BeginRequest, Application_EndRequest, Session_Start etc. are firing for an added ~/Test.aspx, but not for ~/Home/Index which is an MVC controller and action. As soon as I add the runAllManagedModulesForAllRequests="true" flag all event handlers are firing for MVC actions too.
Thanks for your comment. Although, please note line 4 in my code: <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
ReplyDeleteIt is true that some modules will not be fired on MVC pages without the runAllManagedModulesForAllRequests="true" but this is why those modules should be added into added into the modules section (with preCondition="").
Setting runAllManagedModulesForAllRequests="true" will run ALL modules under the sun in EVERY request under the sun (e.g. css files). Using runAllManagedModulesForAllRequests="true" is a kind of brute false 'just make it work' code thats stinks and I believe should be avoided. In my case it was also causing errors.
I agree with what you are saying I just believe that not using that property is best if you can
I don't understand the comment in line 4.
ReplyDeleteAre you saying that any module you want to run in MVC need to be after the UrlRoutingModule line in web.config, or are you saying that they need to also set preCondition="" and deal with getting called on every request?
I THINK that you're saying that they need preCondition=""?
Correct. I wasn't suggesting an order, I was saying the modules needed in MVC will need preCondition=""
ReplyDeleteSome Application events does not get invoked in Global.asax after I set runAllManagedModulesForAllRequests to false. For example this one:
ReplyDeleteApplication_AuthorizeRequest.
I've added these modules to web.config:
Can you give an example of how to add these modules to web.config for events in global.asax that don't fire anymore?
DeleteThanks for the useful info!
ReplyDeleteHi,
ReplyDeleteCould you explain why on 20 windows boxes that are identical to each other in every way possible, our MVC application gives 404 errors on 3 of them unless we add "runAllManagedModules=true" to the web.config?
We've spent an entire day trying to figure this out.
Have you checked your root config files. I.e. machine.config and web.config (the root web.config - the one that is in the same place as the machine.config not the one in the web application)
ReplyDeleteHi, I am recently just trying what you suggest and I have added the module to the web.config and machine.config files of my framework folder.
ReplyDeleteI have also added them too my web.config in my solution.
I still get the same messages, I have restarted my pc several times to ensure it was not an issue with that.
Thanks!
Thank you so much - this solved my problem - I spent about 6 hours trying to fix this! Yay!
ReplyDeletewas very helpful thanks
ReplyDeleteOr you could try this Microsoft Hotfix - http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=5272
ReplyDeleteextensionless URLs worked fine on our dev IIS 7.5 server without needing anything at all in the modules section, but didn't work on our live server. After installing the above hotfix, they 'just worked' on the live server as well.
hi experts,
ReplyDeleteI am facing a very strange problem. If I use,
My all session variables & Forms Authentications User Identity stopped working. I am getting "Object reference not set to an instance of an object." error if I use session variables & authentication Identity.
But If I use "", my problem solved.
Any idea ??
Hi,, Anuj.. I m facing the error.. did u manage to find the solution?
DeleteThanks in Advance.
Regards,
Vani