Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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>

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.

The example with the location tag is literally that. So no path is specified, it is merely the tag <location> so is that actually equivalent to the top example in as much that it encompasses the entire site? – TheEdge May 21, 2015 at 1:00

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.