Configuration File in ASP. NET website development, asp.net website development

Source: Internet
Author: User
Tags website performance

Configuration File in ASP. NET website development, asp.net website development

1. hierarchical classification of configuration files

  1. Machine. config:Overall. netframework Configuration
  2. Web. config (under the framework directory ):Configure public applications for all projects
  3. Web. config (under the Application ):Configuration of the current application (common in the project directory)

2. Running Sequence

The running sequence of configuration files ranges from large to small, from public to private:Machine. config-> (public) web. config->(Private) web. config

The current configuration file determines the configuration information of the Directory and Its subdirectories, And the configuration information under the subdirectory overwrites the configuration of its parent directory, multiple web. in the config file. the config configuration prevails.

 

3. common methods and Problems

1. Access to the MVC custom route fails.

I would like to share with you a problem encountered during MVC development. Many children's shoes may have encountered this problem, that is, custom routing cannot be accessed:

Solution (Add the following configuration ):

<System. webServer>

<! -- Allow access to the path of a custom route -->

<Modules runAllManagedModulesForAllRequests = "true">

<Remove name = "FormsAuthenticationModule"/>

</Modules>

</System. webServer>
2. Reference external configuration files for extension

For example, we have an external configuration file My. Config with the following content:

<? Xml version = "1.0"?>

<Deleetask>

<! -- The data volume that can be submitted on a single page -->

<Add key = "aspnet: MaxHttpCollectionKeys" value = "5000"/>

<! -- Display the number of data rows on a single page -->

<Add key = "PageSize" value = "20"/>

<! -- Whether to send SMS reminder 1 send 0 do not send -->

<Add key = "sendMsg" value = "1"/>

<Add key = "ClientID" value = "1065902100656"/>

</AppSettings>


Reference Method: In web. config:<Etetaskconfigsource = "My. config"/>


3. Custom use of HttpModule and Httphandler 

For custom HttpModule and Httphandler, We need to configure the code to start the work. For example, if a custom MyHttpModule. cs is created, the following configuration must be added to make it take effect:

<! -- IIS6 or IIS7 Classic mode -->

<System. web>

<HttpModules>

<Add name = "mymodule" type = "namespace. MyHttpModule"/>

</HttpModules>

</System. web>

<! -- IIS7 integration mode -->

<System. webServer>

<Modules>

<Add name = "mymodule" type = "namespace. MyHttpModule"/>

</Modules>

</System. webServer>
4. configuration file node description

Root Node: <configuration>

Subnode:

  1. <Deleetask>Node: it is mainly used to store some configuration information of the application. The Value <etettings> is obtained through the Key.
    <Add key = "send" value = "0"/>
    </AppSettings>

2.<ConnectionStrings>Node: used to configure database connections to facilitate the adjustment of database connection information <connectionStrings>
<! -- SQL Server database configuration -->
<Add name = "ConnectionString1" connectionString = "Data Source = 127.0.0.1; Initial Catalog = AspNetStudy; User ID = sa; Password = 12"/>
</ConnectionStrings>


3.<Compilation>Node: Compilation settings. The default debug attribute is "true", that is, debugging is allowed. In this case, the website performance will be affected. Therefore, after the website is launched, it should be set to "false ". <Compilation debug = "true" targetFramework = "4.5"/>


4.<CustomErrors>Node: used to define custom error information <mermerrors mode = "On"/> defaultRedirect Description: indicates the default URLMode to which an application is redirected when an error occurs. Description:
On: displays custom error messages both locally and remotely.
Off: Disable custom error messages. both local and remote users can view 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.

Web. config is a very important configuration file in the asp.net application. This article describes some common basic nodes, so that students can learn more by themselves.

 

We recommend a public technical account:

 

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.