Default Document in Virtual Directory

Topics: General
Sep 21, 2011 at 10:50 PM

I have Orchard installed at the root of my web server and within the Orchard directory structure I have 2 virtual directories that are created as applications. They both have their own web.config files so the html and aspx files within these folders can be accessed. This is all working perfectly thanks to the information I found in other discussions.

When I type the name of the file to be accessed in the sub folder /vts/default.htm everything works great but when I just type the folder name /vts/ it gives me a 404 error. I have added code for the default document in each of my web.config files but this doesn't help because it is not using that web.config file. What do I need to add to the main web.config file to allow my web.config file to 'take control' when I just type the folder name?

Thanks!

Sep 22, 2011 at 12:31 AM

I was wrong about my web.config file, it IS using the one in the virtual directory and I see that the handler is only for a file so I tried changing it to Either and that did not help:

        <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="Either" requireAccess="Read" />


I am completely unfamiliar with this section of the web.config file. I can get the behavior I want by making the custom error in my web.config go to my default page but I know there must be a clean way of doing this.

Coordinator
Sep 22, 2011 at 12:35 AM

It looks like it's the default page that you want to set, not hand everything to the static handler.

Sep 22, 2011 at 12:53 AM
Edited Sep 23, 2011 at 5:28 PM

Thanks for your response, yes that's right I do want to set a default page, how do I stop handing everything to the static handler?

This is my simple web.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="false">
      <remove name="WarmupHttpModule" />
    </modules>
    <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>
    <defaultDocument enabled="true">
      <files>
        <clear/>
        <add value="default.htm" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

what else do I need to add/change to allow for a default document?
Coordinator
Sep 22, 2011 at 12:54 AM

By removing that whole handlers section.

Sep 22, 2011 at 1:12 AM

If I remove it though, the web.config in the root of the Orchard site still has handlers set. if I add the handlers section and clear the handlers I get a 404 error. Can I not just add a handler that controls the directory level?

Sep 22, 2011 at 2:04 AM
Edited Sep 22, 2011 at 2:15 AM

I figured it out:

      <add name="StaticFile" path="*.htm" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
      <add name="StaticDirectory" path="*" verb="*" modules="DefaultDocumentModule" preCondition="integratedMode" resourceType="Directory" requireAccess="Read" />

This works great : )

Sep 23, 2011 at 6:12 PM

My Virtual Directory with the .NET application was more complex because it had aspx pages as well as html, jpg, gif, png, js and css files so I thought I would share the lines that I added to get that working:

        <add name="aspxFile" path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" preCondition="integratedMode" requireAccess="Script"/>
        <add name="StaticFile" path="*.*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
        <add name="StaticDirectory" path="*" verb="*" modules="DefaultDocumentModule" preCondition="integratedMode" resourceType="Either" requireAccess="Read" />