1. Understand the Web. config file
The Web. config file is an XML text file used to store ASP. NET web applications.ProgramConfiguration information (for example, the most common setting of ASP. NET web application authentication method), it can appear in every directory of the application. After you create a web application using VB. NET, a default web application is automatically created in the root directory by default.
The Web. config file, including the default configuration settings, inherits the configuration settings of all subdirectories. If you want to modify the configuration settings of a subdirectory, you can create a web. config file under the subdirectory. It can provide configuration information other than the configuration information inherited from the parent directory, or rewrite or modify the settings defined in the parent directory.
Modifications to the Web. config file at runtime can take effect without restarting the Service (note: the exception in <processmodel> section ). Of course, the Web. config file can be expanded. You can customize new configuration parameters and write the configuration section handler to process them.
Ii. All the following code should be located in the web. config configuration file (default configuration settings)
<Configuration>
<System. Web>
And
< / System. Web>
< / Configuration>
For the purpose of learning, the following examples omit this XML tag.
1 , <Authentication> section
Purpose: Configure ASP. NET authentication support (Windows, forms, passport, none ). This element can only be declared at the computer, site, or application level. The <authentication> element must be used with the <authorization> section.
Example:
In the following example, the website is configured for form-based authentication. When a user who does not log on to the website that requires authentication, the webpage automatically jumps to the logon webpage.
<Authentication Mode = " Forms " >
<Forms loginurl = " Logon. aspx " Name = " . Formsauthcookie " / >
< / Authentication>
The element loginurl indicates the name of the login webpage, and name indicates the cookie name.
2 , <Authorization> section
Purpose: control access to URL resources from clients (for example, Anonymous Users are allowed ). This element can be declared at any level (computer, site, application, subdirectory or page. Must be used with the <authentication> section.
Example: The following example disables access by anonymous users:
<Authorization>
<Deny users = " ? " / >
< / Authorization>
Note: You can use user. Identity. Name to obtain the user name that has been verified. You can use
The Web. Security. formsauthentication. redirectfromloginpage method redirects authenticated users to the page the user just requested. For specific examples, see:
Forms verification http: // Www.fanvb.net/websample/dataauth.aspx
3 , <Compilation> section
Purpose: configure all compilation settings used by ASP. NET. The default debug attribute is "true". After the program is compiled and delivered, set it to true (the web. config file is described in detail, and the example is omitted here)
4 , <Customerrors>
Purpose: Provide information about custom Errors for ASP. NET applications. It is not applicable to errors in XML Web Services.
Example: When an error occurs, redirect the webpage to the custom error page.
<Customerrors defaultredirect = " Errorpage. aspx " Mode = " Remoteonly " >
< / Customerrors>
The defaultredirect element indicates the name of the custom error webpage. Mode element: displays custom (friendly) information for users not running on the Local Web server.
5 , <Httpruntime> section
Purpose: Configure ASP. net http Runtime Library settings. This section can be declared at the computer, site, application, and subdirectory level.
For example, the maximum size of a file to be uploaded is 4 MB, the maximum time is 60 seconds, and the maximum number of requests is 100.
<Httpruntime maxrequestlength = " 4096 " Executiontimeout = " 60 " Apprequestqueuelimit = " 100 " / >
6 , <Pages>
Purpose: Identify page-specific configuration settings (such as whether to enable session Status, view status, and whether to detect user input ). <Pages> statements can be made at the computer, site, application, and subdirectory level.
Example: do not check whether there is potential dangerous data in the content entered by the browser (Note: This item is checked by default. If you do not check, 1. encode or verify user input). When you send a page from the client, the encrypted view status is checked to verify that the view status has been tampered with on the client. (Note: This item is not verified by default)
<Pages Buffer = " True " Enableviewstatemac = " True " Validaterequest = " False " / >
7 , <Sessionstate>
Purpose: Configure session Status settings for the current application (for example, whether to enable session Status and the location where session status is saved ).
Example:
<Sessionstate Mode = " Inproc " Cookieless = " True " Timeout = " 20 " / >
< / Sessionstate>
Note:
Mode = " Inproc " Indicates the local session Status (you can also choose to store the session status on a remote server or Sal server or not enable the session status)
Cookieless = " True " Indicates that the session status is enabled if the browser does not support cookies (the default value is false)
Timeout = " 20 " Indicates the number of minutes in which the session can be idle.
8 , <Trace>
Purpose: configure the ASP. NET tracking service, which is mainly used for program testing to identify errors.
Example: The default configuration in Web. config is as follows:
<Trace enabled = " False " Requestlimit = " 10 " Pageoutput = " False " Tracemode = " Sortbytime " Localonly = " True " / >
Note:
Enabled = " False " Indicates that tracing is not enabled; requestlimit = " 10 " Indicates the number of Trace Requests stored on the server.
Pageoutput = " False " Indicates that the trace output can only be accessed through the tracking utility;
Tracemode = " Sortbytime " Displays trace information in the order of processing traces.
Localonly = " True " Indicates that the trace Viewer (trace. axd) is only used to host web servers.
Iii. custom web. config file configuration section
The configuration section of the custom web. config file consists of two steps.
First, <configsections> and < / Configsections> declare the name of the configuration section and the name of the. NET Framework class that processes the configuration data in this section between the tags.
Second, make actual configuration settings for the declared section after the <configsections> area.
Example: Create a storage database connection string
<Configuration>
<Configsections>
<Section name = " Appsettings " Type = " System. configuration. namevaluefilesectionhandler, system, version = 1.0.3300.0, culture = neutral, publickeytoken = b77a5c561934e089 " / >
< / Configsections>
<Deleetask>
<Add key = " Scon " Value = " Server = A; database = northwind; uid = sa; Pwd = 123 " / >
< / Deleetask>
<System. Web>
< / System. Web>
< / Configuration>
4. access the Web. config file
You can use the configurationsettings. deleettings static string set to access the Web. config file example: Obtain the connection string created in the preceding example.
Dim sconstr as string = Configurationsettings. deleettings ( " Sconstr " )
Dim scon = New sqlconnection (sconstr)
I have forgotten the reprinted address. Sorry.