Know the ASP.NET configuration file Web.config, know the web.config file
The web.config file is an XML text file that is used to store configuration information for the ASP.NET web application (such as the most commonly used setting ASP.NET web application authentication mode), which can appear in every one of the application. Directory. When you create a new web application through VB.NET, you will automatically create a default in the root directory by default.
Web.config files, including default configuration settings, all subdirectories inherit it. If you want to modify the configuration settings for the subdirectories, you can create a new web.config file in the subdirectory. It provides configuration information other than configuration information inherited from the parent directory, or modifies the settings defined in the parent directory.
You can take effect on the modification of the web.config file at runtime. You can take effect (Note:
Second, the web.config configuration file (default configuration settings) should be in all the code
with
configure>
Between, this XML tag is omitted for the example below for the purpose of learning.
1,
Role: Configuring ASP.NET Authentication Support (four of Windows, Forms, Passport, NONE). This element can only be declared at a computer, site, or application level.
Example:
The following example is a Forms-based authentication configuration site, and the web page is automatically jumped to the login web page when the user who does not log in is accessible.
authentication>
The element loginurl indicates the name of the login page, and Name represents the cookie name.
2,
Role: Control client access to the URL resource (such as allowing anonymous user access). This element can be declared on any level (computer, site, application, subdirector). Requirements with
Example: The following example prohibits access to anonymous users
authorization>
Note: You can use User.Identity.name to get the current username that has been verified;
Web.Security.FormSauthentication.RedirectFromLoginPage method Redirects the verified user to the page just requested. For details, please refer:
Forms verification
http://www.fanvb.net/websample/dataAuth.aspx
3,
Role: Configure all compilation settings used by ASP.NET. The default debug property is "true". It should be set to true after the program compile completion delivery is used (the web.config file is described in detail here) 4,
Role: Provides information about custom error messages for the ASP.NET application. It does not apply to errors that have occurred in XML Web Services.
Example: When an error occurs, jump to the custom error page when an error occurs.
CustomerrorS>
The element DEFAULTREDIRECT represents the name of the custom error page. Mode element indicates that the user who is not running on the local web server displays custom (friendly) information.
5,
Role: Configure the ASP.NET HTTP runtime settings. This section can be declared at your computer, site, application, and subdirectories.
Example: Controling the user upload file up to 4m, the maximum time is 60 seconds, the maximum number of requests is 100
6,
Role: Identify the configuration settings specific to the page (if the session state, the view status is enabled, whether the user's input is detected).
Example: Does not detect whether there is potential hazard data in the content entered in the browser (Note: This item is detected, if you use no detection, one to encode or verify the user's input), from the client The encrypted view status will be checked when the page is sent to verify that the view status is tampered with at the client. (Note: This item is not verified by default)
7,
Role: Configure session status settings for the current application (such as setting whether to enable session status, session status storage location).
Example:
sessionState>
Note:
Mode = "invroc" means: store session status locally (you can also choose to store or do not enable session status in remote server or SAL)
CookielesS = "true" means: Enable session status if the user browser does not support cookies (default is false)
Timeout = "20" indicates that the session can be in the number of minutes in idle state
8,
Role: Configure the ASP.NET trace service, which is mainly used for program testing to determine where it is wrong.
Example: The following is the default configuration in Web.config:
Enabled = "false" means not enable tracking; requestLimit = "10" indicates the number of tracking requests stored on the server
PageOutput = "false" means only by tracking utility access tracking output;
TraceMode = "sortbytime" is indicated to display the tracking information in the order of handling tracking.
Localonly = "true" Indicates Track Viewer (Trace.axd) only used for host web servers
Third, custom web.config file configuration section
Custom Web.config file configuration section is divided into two steps.
The first is the name of the configuration section between the "Configuration" The name of the configuration section and the name of the .NET Framework class that processes the configuration data in this section.
The second is the actual configuration settings for the declaration after the
Example: Create a section storage database connection string
configsections>
appsettings>
......
configure>
Fourth, visit the web.config file
You can access the web.config file sample by using the configurationSettings.appsettings static string collection: Get the connection string established in the above example.
DIM Sconstr As String = ConfigurationSettings.AppSettings ("Sconstr")
DIM SCON = New SqlConnection (SCONSTR)
Transfer from:
http://goaler.xicp.net/showlog.asp?id=505