How to add an html page?

Jan 15, 2011 at 9:11 PM

In Orchard 0.8 I was able to add html pages to the site. I had a sub-directory (call it foo) and a set of pages in it.

Assuming the website was at http://www.somesite.com then I could display the about.html page by entering http://www.somesite.com/foo/about.html into the browser.

With Orchard 1.0.20.0 I am getting a 404 error.

Is this a change in behavior between beta and release or a setup error on my part?

Coordinator
Jan 15, 2011 at 9:47 PM

I believe this is the result of the security work we've done on 1.0. To let the web server serve static content files (such as static html pages), you now have to add a specific "web.config" file in the content folder ("foo" in your example). You can find one of these web.config files in any "Content" folder of orchard modules. Note that you should only put static content files in these folders and that all the files will be publicly visible to browsers (i.e. don't put cshtml, ascx files, data files, etc.). Also this web.config files implies applies to all sub-folders recursively (i.e. /foo/bar/static.html will be sucessfully served statically if "/foo" has the web.config file)

Jan 15, 2011 at 11:36 PM
Edited Jan 16, 2011 at 12:11 AM
rpaquay wrote:

I believe this is the result of the security work we've done on 1.0. To let the web server serve static content files (such as static html pages), you now have to add a specific "web.config" file in the content folder ("foo" in your example). You can find one of these web.config files in any "Content" folder of orchard modules. Note that you should only put static content files in these folders and that all the files will be publicly visible to browsers (i.e. don't put cshtml, ascx files, data files, etc.). Also this web.config files implies applies to all sub-folders recursively (i.e. /foo/bar/static.html will be sucessfully served statically if "/foo" has the web.config file)

I copied the default web.config file from the \Media folder and pasted it into \foo and everything now runs.

At this point I would like to understand the contents of this file and what settings are appropriate for this new use? Can I remove un-needed (if any) sections and still achive my goal?

Here is the web.config file that works:

<?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>
    <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>

Coordinator
Jan 16, 2011 at 3:57 AM

The <appSettings> section is to prevent .cshtml files from being run through Razor (I believe)

The <system.web> section is specific to IIS6 and force all files inside the folder and sub-folders to be statically served.

The <systen.webServer> section is specific to IIS7 and force all files inside the folder and sub-folders to be statically served.

I wouldn't recommend removing anything if you want the folder to serve static content only.