4

I cloned a client's Orchard CMS. The repository that I cloned did not contain the Media folder (this is good). So, a next step was to restore the Media/Default directory from a .zip backup. Now that I've restored that, browsing the to site gives a 404 error for all resources in the Media folder. Why?

4

1 回答 1

4

Quick Fix

The /Media folder is missing its required Web.config file. Add it.

Media/Web.config

<?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>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
    </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.
      -->
      <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
    </handlers>
  </system.webServer>
</configuration>

Details

Out-of-the-box, Orchard's Media folder contains a Web.config file. Since source control excluded the Media folder it also did not have its Web.config. In IIS 7+ Integrated Mode, the following config is required for serving static files, because the root Orchard.Web/Web.config file <clear/>s all handlers.

<add name="StaticFile" 
     path="*" 
     verb="*" 
     modules="StaticFileModule" 
     preCondition="integratedMode" 
     resourceType="File" 
     requireAccess="Read" />
于 2014-11-27T02:32:37.673 回答