I use the web. config file by chapter asp. net3.5, some configuration Environments
<? Xml version = "1.0"?>
<Configuration>
<ConfigSections>
<AppSettings/>
<ConnectionStrings/>
<System. web/>
<System. codedom/>
<System. webServer/>
</Configuration>
These are case sensitive and start with lowercase letters.
First, let's talk about <system. web> Settings.
The <system. web> element contains configuration settings for all ASP. NET features. These settings configure various aspects of the web application and enable various services, such as security, status management, and tracing.
The architecture of the <system. web> section is fixed. That is to say, you cannot change or add custom elements here.
Below I will introduce several important parts of web. config.
1. <customErrors/>
This element allows you to configure applications with various HTTP errors. For example, your application creates such a section to redirect annoying 404 errors to display user-friendly error Interfaces
<CustomErrors defaultRedirect = "Error. aspx" mode = "RemoteOnly">
<Error statusCode = "404" redirect = "filenotfound.htm"/>
</CustomErrors>
If the Error code is 404(file not found, the user will be redirected to filenotfound.htm. If other errors occur, the user will be redirected to Error. aspx.
Because the mode is set to RemoteOnly, the local administrator can see the real error information without being redirected. The remote client will only see the custom error page.
Mode has three features:
1. On: the custom error is started. If defaultRedirect is not provided, the user will see a general error.
2. Off: Custom errors are forbidden. The user will see the detailed error message.
3. RemoteOnly
2. <connectionStrings>
This section is a string used to connect to the database.
3. <deleetask>
You can add custom settings in this section.
<Deleetask>
<Add key = "websiteName" value = "My New Website"/>
<Add key = "welcomeMessage" value = "Welcome, friend."/>
</AppSettings>
Can be read from the background code
Configuration config = WebConfigurationManager. OpenWebConfiguration (Request. ApplicationPath );
LblWelcome. Text = config. receivettings. Settings ["welcomeMessage"]. Value;
Or lblSiteName. Text = ConfigurationManager. receivettings ["websiteName"];
To reference a namespace System. Web. Configuration;
Reading non-stored values does not cause errors.
The value of the <deleetask> element in the configuration file is available to all classes of the application and all components used by the application, whether it is a web form class, business logic class, or data validation class. In all these cases, you can use the ConfigurationSettings class in the same way.
A preliminary understanding of the web. config configuration section