Web configuration file web.config is a Web application's data configuration file, which is an XML file that contains settings related to Web application XML tags can be used to simplify the application of related equipment ASP.NET set.
11.7.1 Web based configuration file
Web configuration file web.config in the Web application in any directory, subdirectory if no web.config file, is to inherit the parent directory web.config settings related documents; if there is a subdirectory web.config file to parent directory web.config file override the relevant settings.
. NET Framework is the name of the root configuration file Machine.config, stored in the Windows folder Microsoft.NET \ Framework \ \ CONFIG, the Web server settings for all Web applications are inherited this profile,
air max 2009, if you need to change the settings,
air max sale, use the web.config file in the directory covering relevant settings.
Web configuration file is an XML file,
cheap nike air max shoes, the attributes in the XML tag value is set, tag name and attribute value format is a string,
nike air max 2009, the first one begins with the letter lowercase,
air max 2010 sale, followed by each prefix is capitalized,
air max 2009 sale, such as . Web configuration file example is shown below.
the root of the Web configuration file marks are , his son mark , and is the configuration section. In the settings section under are ASP. NET related settings. Commonly used configuration section tag that is shown in Table 11-9.
Table 11-9 Common Settings section
tag
configuration section
Description
;
control anonymous user Web application, details refer to Chapter 16
set the ASP.NET authentication, see Chapter 13
set ASP.NET user authorization, see Chapter 13
Set up browsing program compatible components HttpBrowserCapabilities
Set compilation mode ASP.NET applications
ASP.NET application to set custom error handling
ASP.NET applications on the global setting, which is localized Set
set HTTP handling corresponds to the URL request is IHttpHandler class
Create, delete, or clear the ASP.NET application's HTTP module
ASP.NET the HTTP implementation of the relevant settings
set the ASP.NET application's user identification is to use server-side user account privileges (impersonate attribute), or the specified user account (userName and password attributes)
set to form the basis of authentication using the Cookie data, and decoding for coded key value
set the ASP.NET Membership mechanism, see Chapter 13
ASP.NET process to set the relevant settings, that is, the properties of the command Page Guidelines
set personal information Porfile objects, details refer to Chapter 14
set the ASP.NET role management, details see Chapter 13
Set Session State ASP.NET application HttpModule
(Continued)
configuration section
Description
set the ASP.NET site navigation system, details refer to Chapter 12
ASP.NET debugging applications, you can Set whether the tracing application execution
Set ASP.NET Web application components, details refer to Chapter 18
set the ASP.NET Web service, details refer to Chapter 18
11.7.2 appSetting with the connectionStrings section of the connection string parameters and
in the Web section of the configuration file program you can create ASP.NET required parameters, ASP.NET 2.0 Add section, you can specify the database connection string.
1. Web web.config configuration file contents
tag in the web.config file
child tag and section, you can create parameters and database connection string, as shown below.
... ... ...
the sub-tag tag is to create arguments, each tag can create a parameter , property key is the parameter name, value is the parameter value.
tag in the sub-tag can also create connection string attribute name is the name, connectionString property is the connection string content.
2. Conifguration API based
ASP.NET 2.0 Configuration API can access the web.config and machine.config configuration file to set data. In the ASP.NET program is to use the name space System.Web.Configuration WebConfigurationManager class to access the settings. First , import the required namespace, as follows.
<% @ Import NameSpace = \
the Import command to import System.Web.Configuration namespace, and then they can get the parameters created section, as shown below.
Dim dbType As String = WebConfigurationManager.AppSettings (\ Use the above code
AppSettings property to get the specified parameters, using the key attribute tag. Section can also obtain the database connection string, as shown below.
Dim pd, db As String
pd = WebConfigurationManager.ConnectionStrings (_
\
db = WebConfigurationManager.ConnectionStrings (_
\
use the ConnectionStrings property to access the program code provider and the database parameter value, that tag name attribute. ASP.NET sample is a complete program Ch11-7-2.aspx, the table shows the performance results using the data table records, as shown in Figure 11-12.
Figure 11-12 Ch11-7-2.aspx operating results
Access Database on the map is a section of the application parameters, data tables is to use the GridView control to display record data, the database connection string is defined in the web.config file.
11.7.3 Session state settings in the sessionState section
ASP.NET Session state management with the scalability, you can set the web.config file Session state management section, it belongs to sub-tags, as shown below.
<sessionState cookieless = \
... ... ...
common property of the tag as shown in Table 11-10.
Table 11-10
common attribute tag
attribute
Description
mode
Session state is stored in the location can be off (not stored), InProc (with Cookie), StateServer (using the state server) and SqlServer (stored in SQL Server)
cookieless
whether to use the Cookie store Session state. True is not in use, False to use
timeout
Session time limit, in minutes, default is 20 minutes, and its function as the Session object of the TimeOut property
11.7.4 globalization section of the code set
subtags in localization of the relevant section is set, you can set the default file encoding ASP.NET program, request and response encoding, date and time formats, and digital and other localization settings as shown below.
<globalization
fileEncoding = \
requestEncoding = \
responseEncoding = \
culture = \
... ... ...
the tag property is set encoding gb2312, culture is a localized setting, zh-CN for the Chinese mainland. Related properties described in Table 11-11 below.
Table 11-11 globalization section
related properties
attribute
Description
requestEncoding
Request request encoding specified, the default is UTF-8 encoding, most of the coding requestEncoding and responseEncoding property should be the same
responseEncoding
Response response
encoding specified, the default is UTF-8 encoding
fileEncoding
specified extension. aspx,. asmx and. asax file default encoding
culture
specify the localization of language areas, different regions have different date and time format, number and so the default localization settings
property value on the table you can use the language culture and the area code, is a culture in Chinese language attribute values shown in Table 11-12.
Table 11-12 culture
property values can use the language and area code
culture attribute value
language or region
zh-HK
Hong Kong
zh-MO
Macau
zh-CN
China
zh -SG
Singapore
zh-TW
Taiwan
zh-CHS
Chinese Simplified
zh-CHT
Chinese Traditional
11.7.5 compilation compiled section setting
marked in sub-section , you can set the default ASP.NET process compilation mode, as shown below.
<compilation defaultLanguage = \
... ... ...
the tag property is set to open the default program language, and whether the debug mode. Related properties described in Table 11-13 below.
Table 11-13 compilation section
related properties
attribute
Description
debug
is turned on debug mode, do not open by default False, True to open
defaultLanguage
default programming language, such as C #, VB or PERL the default is VB
explicit
Microsoft Visual Basic is compiled using the explicit, that is, all variables declared in advance are required, the default value is True
used in the web.config file compilation marking, as the beginning of the program files with ASP.NET Page Language and Debug command properties, as shown below.
<% @ Page Language = \ 11.7.6 customErrors custom error page section
child tag in section, you can set the ASP.NET custom error page program. For example, the error code HTTP 404, as shown in Figure 11-13.
Figure 11-13 displays an error message
the above error message is the default error page, the data shows page not found error. Section can be specified in the error page as shown below.
<customErrors mode = \
... ... ...
The tag property is set
mode On. Related properties described in Table 11-14 below.
Table 11-14 customErrors section
related properties
attribute
Description
mode
whether to start a custom error function, On the custom error handling for the start, then need to specify the defaultRedirect property, Off for the abolition of the custom error handling, RemoteOnly specify a custom error handling is only displayed on the remote client end, the local computer still shows the default ASP . NET error page, this is the default value
defaultRedirect
specified URL address, when an error is generated to redirect the page to this site, this example is shown Ch11-7error. htm page
customErrors section have more than one error in the sub-tags, each tag could error HTTP error codes defined custom error page as shown below.
use of the above error statusCode attribute tag specifies HTTP error code 404, if the error occurs, to redirect to redirect property value NotFoundError.htm page.