Asp.net web. config configuration file node description

Source: Internet
Author: User
Tags configuration settings error status code to domain website performance

Asp tutorial. net web. config configuration file node description
Web. the config file is an xml text file used to store the configuration information of the web application of the asp.net tutorial (for example, the most common method for setting the Authentication Mode of the asp.net web application ), it can appear in every directory of the application. After you create a web application using vb.net, a default web application is automatically created in the root directory by default. config file, including the default configuration settings. All subdirectories inherit its configuration settings. If you want to modify the configuration settings of a subdirectory, you can create a web. config file under the subdirectory. It can provide configuration information other than the configuration information inherited from the parent directory, or rewrite or modify the settings defined in the parent directory. Modifications to the web. config file at runtime can take effect without restarting the Service (note: the exception in <processmodel> section ). Of course, the web. config file can be expanded. You can customize new configuration parameters and write the configuration section handler to process them.

Web. the config file is an xml file whose root node is <configuration>. Common subnodes under the <configuration> node are: <configsections>, <apps tutorial ettings>, <connectionstrings>, and <system. web>. The <etettings> node is mainly used to configure the application configuration information of some websites, and the <connectionstrings> node is mainly used to configure the database tutorial connection string information of the website.
<System. web> A node is mainly configured during website running. Its common nodes are as follows:

<Appsettings> node
<Etettings> A node is used to store configuration information of the asp.net application, such as the storage path of the uploaded file. The following is an example:

1. <deleetask>
2. <! -- Formats of images that can be uploaded -->
3. <add key = "imagetype" value = ".jpg?.bmp =.gif=.png#.jpeg"/>
4. <! -- File type that can be uploaded -->
5. <add key = "filetype" value = ".jpg?.bmp =.gif=.png#.?#.##.zip#.rar=.xls#.doc"/>
6. </appsettings>
You can access the value in the <deleetask> node according to the key. The following is an example of reading the value of the key "filetype" node:

1. string filetype = configurationmanager. receivettings ["filetype"];


<Connectionstrings> node
<Connectionstrings> nodes are mainly used to configure database connections. You can add any node to the <connectionstrings> node to save the database connection string, in the future, you can dynamically obtain the node value in the code to instantiate the database connection object. In this way, once the database connection information changes during deployment, you only need to change the configuration here, you do not need to modify the program code and redeploy the database because of changes in the database connection information.

<Compilation> node
<Compilation> node configuration all the compilation settings used by asp.net. The default debug attribute is "true", that is, debugging is allowed. In this case, the website performance is affected. Therefore, you should set it to "false" after the program compilation is completed and delivered ".

<Authentication> node
Set the asp.net Authentication mode. There are four authentication modes. Their values are as follows:
Mode description
Windows uses windows authentication, applicable to domain users or LAN users.
Forms authentication relies on website developers for identity authentication.
Passport uses the authentication service provided by Microsoft for authentication.
None does not perform any authentication.

<Authentication> node

<Authentication> nodes control the access to websites, directories, or individual pages. They must be used together with <authentication> nodes.

<Customerrors> node
<Customerrors> A node is used to define information about custom error messages. This node has two attributes: mode and defaultredirect. The defaultredirect attribute is an optional attribute, indicating the default url to be redirected when an application error occurs. If this attribute is not specified, a general error is displayed. The mode attribute is a required attribute and has three possible values. They represent the following meanings:
Mode description
On indicates that both local and remote users will see custom error messages.
Off to disable custom error messages. both local and remote users will see detailed error messages.
Remoteonly indicates that the local user will see the detailed error information, and the remote user will see the custom error information.
It is necessary to describe the concept of local and remote users. The machines we use when accessing the asp.net application and when the machines used for publishing the asp.net application are the same machine, they become local users. Otherwise, they are called remote users. In the development and debugging phase, we recommend that you set the mode attribute to off for ease of searching for the error mode attribute. in the deployment phase, you should set the mode attribute to on or remoteonly, this prevents detailed error information from exposing program code details, which can lead to hacker intrusion.

<Error> subnode
The <customerrors> node also contains a <error> subnode, which redirects to our custom error page based on the http error status code of the server, to make the configuration under the <error> subnode take effect, you must set the mode attribute of the <customerrors> node to "on ". The following is an example:

1. <customerrors mode = "on" defaultredirect = "genericerrorpage.htm">
2. <error statuscode = "403" redirect = "403.htm"/>
3. <error statuscode = "404" redirect = "404.htm"/>
4. </customerrors>

Refer pages are all pages we have added. We can provide friendly error messages on the pages.

<Httpruntime> node
<Httpruntime> the node is used to set the http Runtime Library of asp.net. This section can be declared at the computer, site, application, and subdirectory level.
For example, the following configuration controls the maximum size of files that can be uploaded by a user to be 40 MB (40*1024 k), the maximum timeout time is 60 seconds, and the maximum number of concurrent requests is 100.

<Httpruntime maxrequestlength = "40960" executiontimeout = "60" apprequestqueuelimit = "100"/>
<Pages> node
<Pages> A node is used to set a specific page. It has three attributes:
Attribute Name Description
Whether http Response buffer is enabled for buffer.
Whether enableviewstatemac should run the computer authentication check (mac) on The View status of the page to place user tampering. The default value is false. If it is set to true, the performance will decrease.
Validaterequest checks whether there are cross-site scripting and SQL injection vulnerability attacks in user input. The default value is true. If a match occurs, an httprequestvalidationexception occurs. For pages that contain online text editors, set this attribute to false by verifying user input.
The following is an example of configuring nodes:

1. <pages buffer = "true" enableviewstatemac = "true" validaterequest = "false"/>
<Sessionstate> node
<Sessionstate> the node is used to configure the session Status of the current asp.net application. The following is a common Configuration:

1. <sessionstate cookieless = "false" mode = "inproc" timeout = "30"/>
The above node configuration is to enable cookie in the asp.net application, and specify the session state mode to save the session state in the process, and also specify the session timeout to 30 minutes.
The mode attribute of the <sessionstate> node can be one of the following values:
Attribute value description
Custom uses custom data to store session status data.
Default Value of inproc. The asp.net auxiliary process stores session status data.
Off to disable the session status.
Sqlserver uses the SQL server database outside the process to save session status data.
Stateserver uses the out-of-process asp.net Status Service to store status information.
By default, the inproc mode is used to store session state data. The advantage of this mode is that the access speed is fast, and the disadvantage is that it occupies memory, therefore, it is not suitable to store large user session data in this mode.

<Globalization> node:
Used to configure global settings for applications. This node has several important attributes:
Attribute Name Description
Optional attributes of fileencoding. Set the storage encoding of. aspx,. asmx, And. asax files.
Optional requestencoding attributes. Sets the encoding of client requests. The default value is UTF-8.
Optional responseencoding attributes. Sets the server response encoding. The default value is UTF-8.
The following is the default configuration in the asp.net application:

1. <globalization fileencoding = "UTF-8" requestencoding = "UTF-8" responseencoding = "UTF-8"/>


The configuration section of the custom web. config file consists of two steps. First, declare the name of the configuration section and the name of the. net framework class that processes the configuration data in the section between the <configsections> and </configsections> labels at the top of the configuration file. Second, make actual configuration settings for the declared section after the <configsections> area. Example: Create a storage database connection string <configuration> <configsections> <section name = "etettings" type = "system. configuration. namevaluefilesectionhandler, system, version = 1.0.3300.0, culture = neutral, publickeytoken = token "/> </configsections> <appsetctions> <add key =" scon "value =" server =; database = northwind; uid = sa; pwd = 123 "/> </appsettings> <system. web> ...... </system. web> </configuration>

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.