ASP. NET configuration file

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.