TheEdge
TheEdge

Reputation: 9851

Location of system.webServer within web.config

I am struggling to find a definitive schema guide to web.config for an ASP.NET 4.51 WebForms project. With the various web configs I am seeing both of the below and I want to know of both are right, or what the exact difference is.

Is the parent for system.webServer the node configuration like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <system.webServer>
   </system.webServer>
</configuration>

or can it also within a location tag:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <location>
      <system.webServer>
      </system.webServer>
   </location>
</configuration>

Upvotes: 6

Views: 21110

Answers (1)

Juzzbott
Juzzbott

Reputation: 1769

The location element would refer to a specific section of the site, for example, an Administration location or something.

For example, the following web.config example would apply any settings within the <system.webServer> elements only to any resources located within the /admin directory of the site:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <location path="~/admin">
        <system.webServer>
            <security>
                <authentication mode="Forms">
                    <forms name=".ASPXFORMS" loginUrl="/admin/logon.aspx" protection="All" path="/admin" timeout="30" />
                </authentication>
            </security>
        </system.webServer>
    </location>
</configuration>

For application wide <system.webServer> settings, the first example provided (without the location element) is the way to go.

Upvotes: 3

Related Questions