Serving static content directly - bypassing the .NET pipeline

Topics: Core
Feb 4, 2013 at 5:11 PM
Root Orchard Web.Config has this line:
<modules runAllManagedModulesForAllRequests="true">
On a subdir (e.g Themes/VARV/Content), there are web.configs used for serving static content. They work, BUT, are going through the pipeline.

Example – I want this to be a fast 404, it isn’t. It’s slow because it’s actually throwing a 500!

http://www.johnvarvatos.com/Themes/VARV/Content/images/helloworld.gif

If I set that flag above to “false”, static content, images, javascript, etc. don’t go through the pipeline and are served MUCH faster.

I’m struggling with this.

Inside Themes/VARV/Content Web.Config I tried overriding the setting, but it doesn’t work:
<modules runAllManagedModulesForAllRequests="false">
  <clear/>
  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
The requests still go through the pipeline. I don’t want them to!

So my question is, on the root Web.Config, if I set that runAllManagedModulesForAllRequests=false, will it cause any problems? I’ve set it to false and the site SEEMS to be working fine, but I’m not sure.

I found this recent article that does a good job explaining: http://www.west-wind.com/weblog/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78

http://www.hanselman.com/blog/BackToBasicsDynamicImageGenerationASPNETControllersRoutingIHttpHandlersAndRunAllManagedModulesForAllRequests.aspx

But I’m still not sure if I need to go through every Orchard Module config and set the ‘preCondition=true’, if that’s the right approach?
May 21, 2013 at 9:26 PM
Did you ever get a response on this or figure out if it caused side-effects? I am considering setting it to false as well...
Coordinator
May 21, 2013 at 10:35 PM
runAllManagedModulesForAllRequests="false" is the new default in Orchard
May 22, 2013 at 4:51 PM
First off - thank you for the response. We are using Orchard 1.6 and if we switch this setting to false, can you tell us if the out of the box Orchard installation will have any problems? Thanks again...
Aug 26, 2013 at 10:17 AM
Setting this value as true, same as Visual Stuidio does, is much safer than 'false'. On my sites ... after upgrade to Orchard 1.7, I've got 401 http errors on all css and js files. It was hard to find that runAllManagedModulesForAllRequests is responsible for that. Of coz this should work with runAllManagedModulesForAllRequests set as false also and I will try to figure out why setting it to false makes all css files blank.

In my opinion all default settings for Orchard should be set as safe as possible. When some customer doesn't see ORchard working is much wore thing that it works a little bit slowly. There should be a page in documentation for tuning Orchard and there should be explained that runAllManagedModulesForAllRequests can be set to false in some circumstances.
Aug 27, 2013 at 7:41 PM
Yes. We left it as false and that's the ideal setting. The fix for static files failing was simply to comment out the IIS 6 directive, line 9 below. Once that was done, the failed static request issue went away.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>
  <system.web>
    <httpHandlers>
      <!-- iis6 - for any request in this location, return via managed static file handler -->
      <!--<add path="*" verb="*" type="System.Web.StaticFileHandler" />-->
    </httpHandlers>
  </system.web>
  <system.webServer>
    <staticContent>
            <remove fileExtension=".woff" />
            <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
    </staticContent>
    <handlers accessPolicy="Script,Read">
      <!--
      iis7 - for any request to a file exists on disk, return it via native http module.
      accessPolicy 'Script' is to allow for a managed 404 page.
      -->
      <clear/>
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>