Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of system.webServer within web.config

Tags:

asp.net

iis

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>
like image 243
TheEdge Avatar asked Oct 31 '22 03:10

TheEdge


1 Answers

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.

like image 69
Juzzbott Avatar answered Dec 03 '22 21:12

Juzzbott