How do I change where a web.config for a virtual directory in IIS is generated?

15,853

When using IIS Manager, and modifying a directory or virtual directory you can not specify where the new web.config is saved. It goes into that directory.

However, you can get away with not using web.config in any sub-directories and specify specific settings for various sub-directories. In the root web.config, use the location node such as:

<configuration>
    <location path="Departments">
        <system.webServer>
        <defaultDocument>
            <files>
                <add value="blah.htm" />
            </files>
        </defaultDocument>
        </system.webServer>
    </location>
</configuration>

The path is the name of the sub-directory, anything inside the location node is just applied to that path.

If you want to use the GUI, you can use the Configuration Editor to change your settings and choose From:Root web.config at the top.

Share:
15,853
The Vanilla Thrilla
Author by

The Vanilla Thrilla

I'm just an amateur C#/ASP.NET developer with additional experience in C++/Java/Visual Basic.

Updated on June 05, 2022

Comments

  • The Vanilla Thrilla
    The Vanilla Thrilla almost 2 years

    I've created a virtual directory within our intranet web application in IIS 7.5. The virtual directory currently points to the following location:

    \\fileserver\root\Departments

    Whenever I enable directory browsing, it creates a web.config within the Departments folder.

    My question is - Is there a way that I can set this up to change where this web.config file is generated? If possible, I'd like it to be generated in the parent directory aka. \\fileserver\root. Is this possible?