ASP. NET running configuration file

Source: Internet
Author: User

ASP. NET provides two types of configuration files: 1. The machine configuration file machine. config is used for machine-specific settings. 2. Application configuration file web. config -- used for specific application settings

General machine. the config file can be found at: "% SystemRoot % \ Microsoft. NET \ Framework \ V version \ CONFIG \ machine. config "web. config files are generally stored in ASP.. NET file directory.

Configuration File features

When initializing the page, read the machine first. and then read the information stored in the web application root directory. config file, and then ASP. NET continues to enter the next level, read the web in the subdirectory stored in the application root directory. config file, and finally to the ASP..

The configuration file has the following features:

There is a unique root element that can contain all other elements. The root element of machine. config and web. config is <configuration>.

These elements should be enclosed between the corresponding start <start> and end </start>. These tags are case sensitive, so <Start> and <start> should be treated differently.

Any attribute, keyword, or value should be enclosed in double quotation marks: <add key = "data"> </add>

Configuration file structure

In machine. config, its declaration and settings are divided into about 30 configuration blocks, which mainly introduces the three most commonly used parts.

General settings

This part of the configuration file contains the general application configuration settings, such as timeout, maximum request length, and whether to use a fully restricted URL during page redirection, are included in the

<Httpruntime executiontimeout = "180" maxrequestlength = "8192"/> before ASP. NET cancels a request, executiontimeout controls the resource execution time, in seconds, and 90 seconds is the default value. Maxrequestlength specifies the maximum length of the request. 4 MB is the default value. If the request content is greater than 4 MB, you need to add this value.

Page Configuration

Page settings can control the default behavior of ASP. NET pages, such as whether to buffer the output before sending it, or whether to use session status on the application page. Information is stored in the configuration file element. Syntax:

<Pages buffer = "true" enablesessionstate = "true"/> buffer indicates the processing mode of code execution. When it is set to true, all code is executed before any HTML data in the page is rendered. Enablesessionstate indicates whether session variables of the server can be used. The default value is true.

Application settings

Application settings allow you to store application details in the configuration file, without the need to write custom processing programs. For example, set the database connection string:

<Configuration>

<Deleetask>

<Add key = "DSN" value = "Server = SZG-NB; uid = sa; Pwd =; database = pubs"/>

</Appsettings>

</Configuration> Save the configuration file as a file named Web. config. And the application files are saved in the same directory:

<% @ Page Language = "C #" %>

<% String strData = ConfigurationSettings. deleettings ["DSN"]; Response. Write (strData); %>

The program reads the DSN value stored in Web. config, transmits the value to the strData variable, and then uses Response. Wrtie to display it to the browser.

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.