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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With