1

I have a website which needs to use a default document for the application root, but must not for subdirectories. I'm using the "directory browsing" feature, but I only want it to work for subdirectories.

here's a snip of my web.config:

    <system.webServer>
    <defaultDocument enabled="true">
        <files>
            <clear />
            <add value="1f200f74-07e5-4681-a275-e9cbc9f1b794.txt" />
        </files>
    </defaultDocument>
    <directoryBrowse enabled="true" />

I tried applying inheritInChildApplications to the defaultDocument element, but that does not work, actually it makes the application fail. So I want defaultDocument to only apply to the root, and I want to apply directoryBrowse to all subdirectories.

I realize I could have web.config files in each immediate subdirectory, and apply a clear to defaultDocument, but I can't put web.config files in those directories (the nature of this app does not allow that). (Also, allowSubDirConfig doesn't work here, that would just prevent processing of web.config files in subdirectories.)

Is there configuration in web.config which will apply a setting to that node only ?

2 Answers 2

0

The solution is to use Location Tags:

Location tags are used to specify path-specific configuration as an alternative to having a web.config file in the folder mapped to that virtual path. The location tag for a path is set in a parent level in the configuration hierarchy, and is considered to be at that parent level.

See the example at the above link.

0

based on harrymc's answer, I was able to get this configuration to work:

<location path="." inheritInChildApplications="false">
    <system.webServer>
        <defaultDocument enabled="true">
            <files>
                <clear />
                <add value="1f200f74-07e5-4681-a275-e9cbc9f1b794.txt" />
            </files>
        </defaultDocument>
    </system.webServer>
</location>
<system.webServer>
    <!--<defaultDocument enabled="true">
        <files>
            <clear />
            <add value="1f200f74-07e5-4681-a275-e9cbc9f1b794.txt" />
        </files>
    </defaultDocument>-->
    <directoryBrowse enabled="true" />
...

Usage of the inheritInChildApplications attribute in the location element is also necessary. I've left my original "defaultDocument" element in, but commented out as a placeholder for my original attempt.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .