Configure Config.web

Source: Internet
Author: User
Tags config error code http request parent directory xml parser
Web ASP. NET provides a rich and workable configuration system to help managers easily and quickly build their own web application environment. Asp. NET provides a hierarchical configuration architecture that can help Web applications, sites, and machines configure their own extended configuration data separately. Asp. NET's configuration system has the following advantages:
ASP. NET allows configuration content to be placed in the same application directory structure as static content, dynamic pages, and business objects. When a manager needs to install a new ASP.net application, simply copy the application directory to the new machine.
ASP. NET configuration content is saved in plain text and can be interpreted and modified in any standard text editor, XML parser, and scripting language.
ASP.net provides a framework for extending configuration content to support Third-party developers in configuring their own content.
ASP. NET configuration files are automatically monitored by the system, without the manual intervention of the management personnel.

Rules for 4.2.2 Configuration files
Asp. NET's configuration file is a plain text file based on XML format, which is named as "Config.web" under each directory of application. It determines the configuration information for the directory and its subdirectories, and the configuration information under the subdirectory overrides the configuration of its parent directory.
The Winnt\microsoft.net\framework\ version number \ config.web is the root configuration file for the entire machine, which defines the default configuration for the entire environment.
By default, browsers do not have direct access to the Config.web files in the directory.
In the running state, ASP. NET according to the remote URL request, the access path under the various Config.web configuration file overlay, resulting in a unique configuration set. For example, a visit to Url:http://localhost\webapp\owndir\ test.aspx, ASP. NET determines the final configuration according to the following sequence:
1..\microsoft.net\framework\v.1.00\config.web (default configuration file)
2..\webapp\config.web (Applied configuration)
3..\webapp\owndir\config.web (Own configuration)
Syntax rules for 4.2.3 configuration files
1) Identification
The configuration content is placed between the tags <configuration> and </configuration> in the Config.web file.
Format:
<configuration>
Configuration content
...
</configuration>

2 configuration section handle description
Asp. NET's configuration file schema does not specify any file format or supported configuration properties. Instead, it proposes the concept of "configuration segment handle declaration" to support arbitrary user-defined configuration segments.
Format:
<configsections>
<add Name= wants to define the handle function that the configuration segment name type= handle/>
</configsections>

3) configuration Segment
Define the content of the configuration, supply use.

The following example defines a "httpmodules" configuration segment that sets the system HTTP-related processing module

<configuration>

<configsections>
<add name= "httpmodules" type= "System.Web.Configuration.HttpModules
Configurationhandler "/>
</configsections>

<add type= "System.Web.SessionState.CookielessSessionModule"/>
<add type= "System.Web.Caching.OutputCacheModule"/>
<add type= "System.Web.SessionState.SessionStateModule"/>
<add type= "System.Web.Security.WindowsAuthenticationModule"/>
<add type= "System.Web.Security.CookieAuthenticationModule"/>
<add type= "System.Web.Security.PassportAuthenticationModule"/>
<add type= "System.Web.Security.CustomAuthenticationModule"/>
<add type= "System.Web.Security.UrlAuthorizationModule"/>
<add type= "System.Web.Security.FileAuthorizationModule"/>

</configuration>

4.2.4 ASP. NET-defined standard configuration segment
1 HttpModule segment: Defines the processing module of the HTTP request applied and the application methods such as security, log, etc.
2 httphandlers Segment: Responsible for mapping URLs to IHttpHandler classes
3) Sessionstat segment: Responsible for configuring the session state of the HTTP module
4) Globalization section: Configure the common settings for the application
5) Compilation segment: Configure the ASP.net compilation environment
6 Trace Segment: Configure ASP.net tracking service
7) Security Section: ASP. NET's security Configuration
8 Iisprocessmodel segment: Configure asp.net processing mode on IIS
9) browercaps segment: Configuring compatible parts for browsers
4.2.51 configurations read out examples
1) config.web configuration file

<!--config.web Please put in formcfg.aspx directory-->
<configuration>
<!--declare a test configuration segment-->
<configsections>
<add name= "test" type= "System.Web.Configuration.DictionarySectionHandler"/>
</configsections>

<test>
<!--Configure a key, which is the content of just a configure test-->

<add key= "key" value= "Just a Configure test"/>
</test>

</configuration>

2) read out its contents

<!--filename:application/formcfg.aspx-->
<script language= "VB" runat=server>
Sub Page_Load (S as Object, E as EventArgs)
' Remove the value of the key key for the test configuration segment
Dim cfgsection as Hashtable = Context.getconfig ("Test")
Dim Msg as String = CStr (cfgsection ("key"))

Lblmsg.text=msg
End Sub
</script>
<title>
Read the configuration information
</title>

<body>
<center>
The contents of key in the "Test" configuration section in Config.web are:
<asp:label id=lblmsg runat=server/>
</center>
</body>


3) Running Results



4.2 6 Config.web Configuration Instance
<configuration>
<!--define common settings that users apply, such as SQL SQL connection strings, and so on-->
<appsettings>
</appsettings>

<!--set the browser compatibility part-->
<browsercaps>
</browsercaps>

<!--compilation environment settings, non-debug mode-->
<compilation debugmode= "false" >
<!--The default compilation language is VB, and you can no longer define the scripting language in page-->
<compilers defaultlanguage= "VB" >
<!--compiled with MSVSA.dll. vb file--> with VB as suffix
<compiler language= "vb" extension= ". vb" type= "Msvsa.dll#microsoft.vb.compiler"/>
</compilers>

<assemblies>
<!--add a reference to System.Data-->
<add assembly= "System.Data"/>
<!--Remove References to System.Data-->
<remove assembly= "System.IO"/>
<!--remove references contained in or inherited from Config.web-->
<clear/>
</assemblies>

</compilation>

<!--settings apply Global Environment-->
<!--file, request, return GB2312 encoding to ensure that the browser correctly displays the Chinese-->
<globalization fileencoding= "gb2312" requestencoding= "gb2312"
responseencoding= "gb2312"/>

<!--define the handling of user errors-->
<!--error The default display defaultredirect specified page, mode is on, follow customerrors configuration segment-->
<!--mode is off, ignore user error, Mode is RemoteOnly, local only show the real error reason-->
<customerrors defaultredirect= "Anerrorhasoccured.aspx? Errnum=-1 "mode=" remote ">
<!--displays the page specified by redirect when the error code is 500-->
<error statuscode= "redirect=" anerrorhasoccured.aspx? Errnum=500 "/>
</customerrors>

<!--access permissions for the specified directory WebApp-->
<location path= "WebApp" >
<!--unauthorized users cannot enter the WebApp directory-->
<security>
<authorization>
<deny users= "?"/>
</authorization>
</security>
</location>

<!--define security attributes-->
<security>
<authorization>
<!--role to access its specified resources for adminstrators and all users-->
<allow roles= "adminstrators"/>
<allow users= "*"/>
</authorization>
</security>

</configuration>



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.