Asp. NET configuration file Web. config detailed explanation

Source: Internet
Author: User
Tags configuration settings

I. Understanding the Web. config file

The Web. config file is an XML text file that is used to store ASPconfiguration information for. NET WEB applications , such as the most common settings for ASP. NET WEB application), which can appear in every directory in the application. When you create a new Web application through vb.net, by default, a default Web. config file is automatically created in the root directory, including the default configuration settings, and all subdirectories inherit its configuration settings. If you want to modify the configuration settings for subdirectories, you can create a new Web. config file under that subdirectory.           It can provide configuration information other than the configuration information inherited from the parent directory, or you can override or modify the settings defined in the parent directory. Modifications to the Web. config file at run time do not need to restart the service to take effect (note: section exceptions). Of course, the Web. config file can be extended.    You can customize the new configuration parameters and write configuration section handlers to process them. Ii. Web. configconfiguration file (default configuration settings) All of the following code should be in and between, and for the purposes of learning the following example omits this XML tag1. Section role: Configure ASP. NET authentication support (for Windows, Forms, PassPort, none four). The element can only bemachine, site, or application level declaration. Elements must be used in conjunction with a section. Example: The following example configures a site for forms-based authentication when there is no loginThe user accesses a webpage that requires authentication, and the webpage automatically jumps to the landing page.
<authentication mode= "Forms" > <forms loginurl= "logon. aspx "Name=". Formsauthcookie "/> </authentication>
where element loginurl represents the name of the landing page, name indicates cookie Name 2, section action: Controls client access to the URL resource (such as allowing anonymous user access). This element can be declared at any level (computer, site, application, subdirectory, or page).        Must be used in conjunction with the section. Example: The following example disables access for anonymous users
<authorization> <deny users= "?" /> </authorization>
Note: You can use User.Identity.Name to get the current user name that has been verified, and you can use the Web. The Security.FormsAuthentication.RedirectFromLoginPage method redirects the authenticated user to the page that the user just requested. For specific examples, please refer to: Forms verification http://www.51aspx.com /websample/dataauth.aspx3. Node Action: Configures all compilation settings used by ASP. The default Debug property is "true". It should be set to true after the program has been compiled for delivery (in the Web. config file, where the example is omitted) 4, the role: Provides information about custom error messages for ASP.        It does not apply to errors that occur in XML Web services. Example: When an error occurs, the Web page jumps to the custom error page.
<customerrors defaultredirect= "errorpage.aspx" mode= "RemoteOnly" > </customErrors>
where element defaultredirect represents the name of the custom error page. The mode element means: Yes, not on the local Webusers running on the server display custom (friendly) information. 5. Section Action: Configure the ASP. NET HTTP runtime settings.   This section can be declared at the machine, site, application, and subdirectory levels. Example: Control user upload file up to 4M, maximum time 60 seconds, maximum number of requests is 100 6, Role: Identify page-specific configuration settings (such as whether to enable session state, view state, whether to detect user input, etc.).   Can be declared at the machine, site, application, and subdirectory levels. Example: Do not detect a user's input in the browser for potentially dangerous data (note: The item is detected by default, if you use no detection, one to encode or verify the user's input), the encrypted view state is checked when the page is posted back from the client to verify that the view state has been tampered with on the client.   (Note: This item is not verified by default) 7, role: Configure session state settings for the current application (such as setting whether session state is enabled, session state save location). Example:
<sessionstate mode= "InProc" cookieless= "true" timeout= "
/>" </sessionState>
Note: mode= "InProc" means: Store session state locally (you can also choose to store it in a remote server or SAL server or not enable session state) Cookieless= "True" indicates that session state is enabled if the user's browser does not support cookies (   The default is False) timeout= "20" means: The number of minutes that a session can be idle 8, function: Configure the ASP. NET tracking service, mainly used for program testing to determine where errors occur. Example: The following is the default configuration in Web. config: note: enabled= "false" means no tracing is enabled; requestlimit= "10" indicates the number of trace requests stored on the server pageoutput= "false" means that only the Tracing utility to access trace output; tracemode= "SortByTime" means to display trace information in the order in which the traces are processed localonly= "true" means that the trace viewer (Trace.axd) is used only for hosting WEB servers. Custom WEB.C    The Onfig file configuration section is a two-step process for customizing the Web. config file configuration section.   The first is to declare the name of the configuration section and the name of the. NET Framework class that handles the configuration data in that section, between the top of the configuration file and the markup.   The second is to make the actual configuration settings for the declared section after the zone. Example: Create a section StoreDatabase connection String
<configuration> <configSections> <section name= "appSettings" type= "System.Configuration.NameVal Uefilesectionhandler, System, version=1.0.3300.0, culture=neutral, publickeytoken=b77a5c561934e089 "/> </ configsections> <appSettings> <add key= "Scon" value= "server=a;database=northwind;uid=sa;pwd=123"/>    ; </appSettings> <system.web> ... </system.web> </configuration>
Iv. Accessing the Web. config fileYou can access the Web. config file example by using the ConfigurationSettings.AppSettings static string collection: Gets the connection string established in the example above.

Asp. NET configuration file Web. config detailed explanation

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.