1. the ASP. NET configuration file adopts an inheritance relationship, which is: machine. config --> Web. config --> folder web. config.
2. For <location/> node nodes, When configuring permissions, we use web. config to restrict access to folders or files under the website directory. For example:
<! -- Restrict the folder admin1 -->
< Location Path = " Admin1 " >
< System. Web >
< Authorization >
< Allow roles = " -100,1, 2 " />
< Deny users = " * " />
</ Authorization >
</ System. Web >
</ Location >
<! -- Restrict the folder admin2 and the file admin2.aspx. -->
< Location Path = " Admin2 \ admin2.aspx " >
< System. Web >
< Authorization >
< Allow roles = " -100,3, 4 " />
< Deny users = " * " />
</ Authorization >
</ System. Web >
</ Location >
3. For the lockattributes, lockelements, lockallattributesexcept, and lockallelementsexcept attributes, it indicates that a certain attribute or node is locked. The attributes inherited from its configuration file cannot be overwritten, for example:
<Membership lockelements="Providers" Lockattributes="Defaultprovider, hashalgorithmtype">
4. to read and write configuration files, read the configuration file first. We all know that the configuration file is an XML file. We can read and write the configuration file in XML mode. However, in ASP. in. net, Ms provides a set of strong APIs to read and write configuration files, such:
// Read operation:
Using System. Web. configuration;
Using System. configuration;
Namespace Confingdemo
{
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Membershipsection MS =
(Membershipsection)
Webconfigurationmanager. getsection ( " System. Web/Membership " , " ~ /Web. config " );
Response. Write ( " The default provider as set in config is: " + Ms. defaultprovider + " <Br/> " );
}
}
}
// Write operation:
Using System. Web. configuration;
Using System. configuration;
Namespace Confingdemo
{
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Configuration config = Webconfigurationmanager. openwebconfiguration ( " ~ " );
Membershipsection MS = (Membershipsection) config. getsection ( " System. Web/Membership " );
Ms. defaultprovider = " Someotherprovider " ;
Config. Save ();
}
}
}
If you have any questions or errors, you are welcome to correct and discuss them.