Web. config

Source: Internet
Author: User
Tags configuration settings

Ylbtech-miscellaneos:web.config
The Web. config file is an XML text file that is used to store configuration information for the Asp.netweb application (such as the most commonly used settings Asp.netweb the authentication method of the application), which can appear in each directory of the application. When you pass. NET creates a new Web application, 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). In addition, the Web. config file can also be extended. You can customize the new configuration parameters and write configuration section handlers to process them.
Chinese name:
foreign name: web.config
     quality: is an XML text file
for      use: used to store asp.netweb& nbsp; configuration information
out      now: In each directory of the application
Superior      point: modify does not need to restart the service to take effect
1. Configuration back to top
Web configuration file (*.config)
2. configuration file back to top
(Default configuration settings) All of the following code should be between <configuration> and </configuration>, for easy and intuitive learning, the following example omits this XML tag 1, < authentication> section function: Configure ASP. NET authentication support (for Windows, Forms, PassPort, none four). This element can only be declared at the machine, site, or application level. Elements must be used in conjunction with a section. Example: The following example configures a site for forms-based authentication, and when no logged-on user accesses a webpage that requires authentication, the webpage automatically jumps to the landing page. where element loginurl represents the name of the landing page, name indicates the cookie name 2, <authorization> function: Controls client access to the URL resource (such as allowing anonymous user access). This section 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 note: You can use User.Identity.Name to obtain the current user name that has been verified; You can use the Web.Security.FormsAuthentication.RedirectFromLoginPage method to verify Redirect the user to the page that the user just requested. 3, <compilation> function: Configures all compilation settings used by ASP. The default Debug property is "True". You should set it to "False" after the program has been compiled for delivery (the Web. config file has detailed instructions, omitting the example here) 4, <customErrors> Section Effect: 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. where element defaultredirect represents the name of the custom error page. The mode element indicates that the custom information is displayed for users who are not running on the local Web server. 5. 3. Custom Web. config file configuration back to top Customizing the Web. config file configuration section is a two-step process. 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 to store a database connection string <configuration><configsections><section name= "AppSettings" type= " System.Configuration.NameValueFileSectionHandler, 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>
4. access the Web. config file configuration back to top
You can access the Web. config file by using the ConfigurationSettings.AppSettings static string collection. Example: Get the connection string established in the example above. Vb.netdim sconstr as String = System.Configuration.ConfigurationManager.AppSettings ("ConnectionString") c#string ConnectionString =system.configuration.configurationmanager.appsettings["connectionString"];
5. create a Web. config file configuration back to top
1. In Solution Explorer, click the Refresh icon to confirm that the application does not yet have a Web. config file. If you have used the Web Site Administration tool or some other way to configure your application, the Web. config file may have been created automatically. Click Refresh to update the file list. 2. In Solution Explorer, right-click the site name, and then click Add New Item. 3. In the Templates window, click Web configuration file. The file name in the Name text box should be Web. config. You can provide a different name for the file, but this is the default name. The. config file name extension prevents ASP. NET from downloading the appropriate file. 4. Click Add to create the file, and then open it for editing. The file contains the code shown in the "Examples" section later in this topic and has some initial default values. The application inherits all configuration settings from the Machine.config and Web. config files in the%systemroot%\microsoft.net\framework\< version >\config directory. However, these default settings are not visible here. If you want to override inherited default settings or add collection elements such as the httphandlers element (ASP. NET setting Schema), you only need to create the application-level and directory-level Web. config files. To view all the configuration settings for the current application, you can run the topic How to: Programmatically View inherited configuration settings and code that is contained in local configuration settings. You can also view the Machine.config.comments or Web.config.comments in the%systemroot%\microsoft.net\framework\< version >\config directory File (these two files also contain useful comments), but these two files will not contain all runtime settings, see How to: Programmatically View inherited configuration settings and local configuration settings. 5. If the Web. config file is changed, save the file. Saving the Web. config file restarts the application. You can also choose to point to a secondary profile using the ConfigSource property of a single section element, and changing the secondary profile does not cause the application to restart. For more information, see ConfigSource in the General properties inherited by section elements.  
6. Extend back to top
6.1 Baidu Encyclopedia Https://baike.baidu.com/item/web.config
7. back to top
8. back to top
9. back to top
Ylbtech
Source: http://ylbtech.cnblogs.com/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Web. config

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.