Know the ASP.NET configuration file Web.config

xiaoxiao2021-03-05  21

First, know the web.config file web.config file is an XML text file, which is used to store configuration information for the ASP.NET web application (such as the most commonly used settings of the ASP.NET web application authentication method), it can Announces in each directory of the application. When you create a web application through VB.NET, you will automatically create a default web.config file in the root directory by default, including the 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:

Festival exceptions). Of course, the web.config file can be expanded. You can customize the new configuration parameters and write a configuration segment process program to process them. Second, the web.config configuration file (default configuration settings) should be in all the code

with

Between, this XML mark 1 is omitted for the example below for learning purposes.

Action: Configuring ASP.NET authentication support (for Windows, Forms, Passport, None). This element can only be declared at a computer, site, or application level.

Element must

The section is used. Example: The following example is a Forms-based authentication configuration site that automatically jumps to the login page.

The element Loginurl indicates the name of the landing page, named the cookie name 2,

Action: Controls client access to the URL resource (such as allowing anonymous users to access). This element can be declared on any level (computer, site, application, subdirector). Asked

The section is used. Example: The following example prohibits access to anonymous users

Note: You can use user.Identity.name to get the current username that has been verified; you can use the web.security.formloginpage method to redirect the verified user to the page just requested. For details, please refer to : Forms Verification http://www.fanvb.net/websample/dataAuth.aspx 3,

Square: Configure all compilation settings used by ASP.NET. The default debug property is "true". It should be set to true after the program compilation completion delivery is used (the web.config file is described in detail, and the example is omitted) 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.

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,

Square: 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).

You can declare on your computer, site, application, and subdirectories. 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 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:

Note: Mode = "inproc" means: store session status locally (you can also choose to store or do not enable session status) cookieless = "true" means: If the user browser does not support cookie, enable session State (default is false) Timeout = "20" means: the session can be in the number of minutes of the idle state,

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:

Note: Enabled = "false" means not enable tracking; RequestLimit = "10" indicates that the number of trace requests specifying the trace requests stored on the server will use only by tracking utility access tracking output; TraceMode = "sortbytime" means Display tracking information locaLonly = "true" to handle tracking, TRACALONLY = "TRACE.axd) is only used for host web server three, custom web.config file configuration section custom web.config file configuration process division Two steps. First, in the top of the configuration file

with

The name of the configuration section between the tag and the name of the .NET Framework class that handles the configuration data in this section. Second is

The area after the region is the actual configuration setting. Example: Create a section storage database connection string

......

Fourth, access the web.config file You can access the web.config file example 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)

转载请注明原文地址:https://www.9cbs.com/read-37969.html

New Post(0)