asp.net Night Talk of 11: web.config Xiangjie (Reprinted)

asp.net Night Talk of 11: web.config Xiangjie

Often encountered in the development of such a situation, the deployment process to maintain secrecy is not the time to release the source code together with the project, and our development and deployment environment when the environment may be inconsistent (eg different databases), if the code Save the configuration to deploy this information to the user where changes need to recompile the code again, this deployment is very troublesome. In. Net provides a convenient way to save the project configuration information, it is to use configuration files, configuration files files suffix generally. Config, the configuration file in asp.net General default web.config. Each web.config file is a text file based on XML and can be saved to the Web application in any directory. Web publishing application in web.config file is not compiled into the dll file. If a change in the future, the client only need to use Notepad to open the web.config file you can edit the settings related to the normal re-use, very convenient.
This knowledge should be described as follows:
Find the profile priority profile shows the profile of the operation node

Configuration file to find priority in. Net provides a view of the current machine configuration file, this file is machine.config, which is located in% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ CONFIG \ documents under (% windir% is the system directory under the system partition, the command line mode, enter% windir% and press Enter the machines will be able to view the current system directory, in Windows2003 and WindowsXP in the% windir% is the system partition under the windows directory, in the% windir Windows2000 % is the system partition under the WinNT directory, the author of this machine system directory is C: \ WINDOWS). The document which defines the procedures for the current and the asp.net machine WinForm application configuration. The following is the contents of machine.config file:
In this folder there is a web.config file, this file contains the common asp.net web site configuration. The following is the web.config file:
asp.net web site will be loaded when the IIS start configuration file in the configuration information, and then cache that information, so you do not have time to read the configuration information. Running asp.net application process will monitor the changes in configuration file, once edited the configuration information, will be re-read the configuration information and cache.

When we read a node or node group information, is searched in accordance with the following way:

(1) If the current page exists in the directory where the web.config file to see if there are to find the node name, returns the result and stop if there is to find.

(2) if the current page where the directory does not exist in the web.config file or the web.config file does not exist in the node name, then find its parent directory, until the site's root directory.

(3) If the site does not exist under the root directory web.config file or web.config file does not exist in the node name in the% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ CONFIG \ web.config file to find.

(4) If the% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ CONFIG \ web.config file does not exist in the corresponding node in the% windir% \ Microsoft.NET \ Framework \ v2.0.50727 \ CONFIG \ machine.config file search.

(5) If still not found then return null.

So if we are to a website or a folder with a specific configuration requirements, you can create the appropriate folder a web.config file override the parent folder of the same name in the web.config file you can configure. The configuration information of the search only to find one, it would be cached for subsequent calls. In the asp.net application is running, if the web.config file changes will lead to a corresponding application to restart, then stored in the server memory in the user session information is lost (as stored in the memory of the Session) . Some software (such as antivirus software) for each completed visit in web.config web.config will modify the access time attribute, can lead to asp.net application restart.

Node configuration file description

web.config file is an XML file, its root node is <configuration>, <configuration> node in the common child nodes are: <configSections>, <appSettings>, <connectionStrings> and <system.web>. <appSettings> Node which is mainly used for configuration of some Web application configuration information, and is mainly used for configuration site <connectionStrings> node database connection string information.

<system.web> node is the site run mainly to some of the configuration, it's common nodes are as follows:

<appSettings> node

<appSettings> node asp.net application is mainly used to store some configuration information, such as upload the file save path, etc. The following is an example:

<appSettings>
<! - Allows upload the image format type ->
<addkey="ImageType"value=".jpg;.bmp;.gif;.png;.jpeg"/>
<! - Allow upload file types ->
<addkey="FileType"value=".jpg;.bmp;.gif;.png;.jpeg;.pdf;.zip;.rar;.xls;.doc"/>
</ AppSettings>
For <appSettings> node value can be carried out in accordance with key access, the following is a read key value "FileType" Node value examples:

stringfileType = ConfigurationManager.AppSettings ["FileType"];

<connectionStrings> node

<connectionStrings> mainly used to configure the database connection node, we can add any number of <connectionStrings> node node to save the database connection string in the future through the code in the code the way the value of the dynamic access node to an instance of database connection objects Once the deployment of such a database connection information changes when we only need to change the configuration can be here, without having to change because the database connection information need change code and re-deployment.

The following is an example of <connectionStrings> node configuration:

<connectionStrings>
<! - SQLServer database configuration ->
<addname="AspNetStudyConnectionString1"connectionString="DataSource=(local);InitialCatalog=AspNetStudy;UserID=sa;Password=sa"/>
</ ConnectionStrings>
In the code so we can instantiate database connection object:

/ / Read the web.config node configuration
stringconnectionString = ConfigurationManager.ConnectionStrings ["AspNetStudyConnectionString1"]. ConnectionString;
/ / Instantiate the SqlConnection object
SqlConnectionconnection = newSqlConnection (connectionString);
The benefit of this is that once the development of the database and used by the deployment of the database is inconsistent, just need to use Notepad text editor edit the connectionString value of the property on the line.

<compilation> node

<compilation> node configuration for all compilation settings used by ASP.NET. The default debug attribute is "true", which allows debugging, in this case will affect the site's performance, so the program finished compiling it should be set after the delivery of "false".

<authentication> node set asp.net authentication mode, there are four types of authentication mode, their values are as follows:

Mode Description

Windows to use Windows authentication for domain users or local area network users.

Forms to use forms authentication, relying on web developers to authenticate.

Use Microsoft Passport provides authentication services to authenticate.

None without any authentication.

<authentication> node

<authentication> node control user Web site, directory or individual page access node to be used in conjunction with the <authentication>.

<customErrors> node

<customErrors> node is used to define some custom error message information. Mode and defaultRedirect this node has two properties, which defaultRedirect attribute is an optional attribute that when an error occurs the application redirect to the default URL, if the property is not specified, the general error is displayed. Required Mode property is a property, it has three possible values, meaning they represent are as follows:

Mode Description

On the local and remote users that will see the custom error message.

Off to disable custom error messages, local and remote users will see the detailed error message.

RemoteOnly that local users will see the detailed error information, and the remote user will see a custom error message.

There is need to explain the local users and remote users of the concept. Access asp.net application that we use when publishing asp.net application machine and the machine used for the same machine when a local user, otherwise known as the remote user. In order to facilitate debugging in the development stage to find the error proposals Mode property is set to Off, and Mode attribute in the deployment phase should be set to On or RemoteOnly, in order to avoid the detailed error code information revealed details of which lead to hackers.

Now we add a page CustomErrorsDemo.aspx, in its Page_Load event where an exception is thrown, the code is as follows:

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
publicpartialclassCustomErrorsDemo: System.Web.UI.Page
(
voidPage_Load () voidPage_Load (objectsender, EventArgse)
(
thrownewException ("intentionally thrown the exception.");
)
)

We first configure <customErrors> as follows:
<customErrorsmode="RemoteOnly">
<errorstatusCode="403"redirect="NoAccess.htm"/>
<errorstatusCode="404"redirect="FileNotFound.htm"/>
</ CustomErrors>
Then the effect of the local running CustomErrorsDemo.aspx as follows:
Remote access see the effects:
If we customErrors the Mode property is set to "On" the local operation and remote access will see the following effects:
If customErrors the Mode property is set to "Off" local operation and remote access will see the following effects:
<error> child node in the node also contains <customErrors> <error> child nodes, the nodes are mainly based on the HTTP server error status code and redirect to our custom error page, pay attention to the child nodes to make <error> under the configuration to take effect, must be <customErrors> node node Mode attribute set to "On". Here is an example:
<customErrorsmode="On"defaultRedirect="GenericErrorPage.htm">
<errorstatusCode="403"redirect="403.htm"/>
<errorstatusCode="404"redirect="404.htm"/>
</ CustomErrors>
In the above configuration to access the page if the user does not exist it will jump to the 404.htm page, if the user does not have permission to access the requested page will jump to the 403.htm page, 403.htm 404.htm page and are add our own pages, we can give the page a friendly error message.

<httpHandlers> node
<httpHandlers> node for the user requests the URL and the HTTP verb to the user's request to the appropriate handler. Can be any level in the configuration-level configuration of this node, that can be specified for a particular directory, special file special handling.

The following is the same directory with the machine.config file under the web.config file <httpHandlers> node configuration:
<httpHandlers>
<addpath="*.rules"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.xoml"verb="*"type="System.ServiceModel.Activation.HttpHandler,System.ServiceModel,Version=3.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"validate="false"/>
<addpath="trace.axd"verb="*"type="System.Web.Handlers.TraceHandler"validate="true"/>
<addpath="WebResource.axd"verb="GET"type="System.Web.Handlers.AssemblyResourceLoader"validate="true"/>
<addpath="*.axd"verb="*"type="System.Web.HttpNotFoundHandler"validate="true"/>
<addpath="*.aspx"verb="*"type="System.Web.UI.PageHandlerFactory"validate="true"/>
<addpath="*.ashx"verb="*"type="System.Web.UI.SimpleHandlerFactory"validate="true"/>
<Addpath = "*. asmx" verb = "*" type = "System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" validate = "false "/>
<Addpath = "*. rem" verb = "*" type = "System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" validate = "false" />
<Addpath = "*. soap" verb = "*" type = "System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089" validate = "false" />
<addpath="*.asax"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.ascx"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.master"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.skin"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.browser"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.sitemap"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.dll.config"verb="GET,HEAD"type="System.Web.StaticFileHandler"validate="true"/>
<addpath="*.exe.config"verb="GET,HEAD"type="System.Web.StaticFileHandler"validate="true"/>
<addpath="*.config"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.cs"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.csproj"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.vb"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.vbproj"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.webinfo"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.licx"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.resx"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.resources"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.mdb"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.vjsproj"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.java"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.jsl"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.ldb"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.ad"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.dd"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.ldd"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.sd"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.cd"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.adprototype"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.lddprototype"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.sdm"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.sdmDocument"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.mdf"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.ldf"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.exclude"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.refresh"verb="*"type="System.Web.HttpForbiddenHandler"validate="true"/>
<addpath="*.svc"verb="*"type="System.ServiceModel.Activation.HttpHandler,System.ServiceModel,Version=3.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"validate="false"/>
<addpath="*"verb="GET,HEAD,POST"type="System.Web.DefaultHttpHandler"validate="true"/>
<addpath="*"verb="*"type="System.Web.HttpMethodNotAllowedHandler"validate="true"/>
</ HttpHandlers>

From the above configuration can be seen, for *. mdf, *. ldf files in the Get or Post request will be dealt to the System.Web.HttpForbiddenHandler, processing the results is that users can not view or download files. If the file to a folder or a file type does not allow users to download, you can </ httpHandlers> node to add the corresponding child nodes.
Here we have an example to illustrate the use of <httpHandlers> node in our asp.net application to establish a IPData directory, create a directory in IPData IPData.txt file, and then add the following configuration in the Web.config:
<httpHandlers>
<addpath="IPData/*.txt"verb="*"type="System.Web.HttpForbiddenHandler"/>
</ HttpHandlers>

The role of the above code to prohibit any access to IPData directory txt file.
Then create a new page, the page to add a hyperlink to link to the directory IPData.txt file, the code is as follows:
<% @ PageLanguage = "C #" AutoEventWireup = "true" CodeFile = "HttpHandlersDemo.aspx.cs" Inherits = "HttpHandlersDemo"%>
<! DOCTYPEhtmlPUBLIC "- / / W3C / / DTDXHTML1.0Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title> httpHandlers node of the example </ title>
</ Head>
<body>
<formid="form1"runat="server">
<div>
<ahref="IPData/IPData.txt"title=" Open IPData/IPData.txt"> open IPData / IPData.txt </ a>
</ Div>
</ Form>
</ Body>
</ Html>
The effect of running this page is as follows:
<customErrors> The current node configuration web.config file as follows:
<customErrorsmode="On"defaultRedirect="GenericErrorPage.htm">
<errorstatusCode="403"redirect="403.htm"/>
<errorstatusCode="404"redirect="404.htm"/>
</ CustomErrors>
And if there 403.htm 404.htm page, click the following hyperlink will appear after the effect of:
We can see from the image above when <customErrors> node Mode attribute to "On", because the folder was barred from visiting IPData All txt files, it will jump to a custom page without permission to suggest that the 403 . htm.

<httpRuntime> node
<httpRuntime> node used ASP.NETHTTP runtime settings. This section can be in the computer, site, application, and subdirectory level statement.
For example, the following configuration control of the largest users can upload files to 40M (40 * 1024K), the maximum timeout of 60 seconds, maximum of 100 concurrent requests.
<httpRuntimemaxRequestLength="40960"executionTimeout="60"appRequestQueueLimit="100"/>

<pages> node
<pages> node used to represent a specific page settings, there are three main attributes are as follows:
Property Name Description
buffer is enabled, HTTP response buffer.
enableViewStateMac whether the page view state should run the computer authentication check (MAC), to place the user tampering, defaults to false, if set to true will cause performance degradation.
validateRequest validate user input, there is cross-site scripting attacks and SQL injection exploits, default is true, if the situation matches the exception will be made HttpRequestValidationException. The line contains the page text editor and general self-validate user input this property to false.
Here is an example of a configuration node:
<pagesbuffer="true"enableViewStateMac="true"validateRequest="false"/>

<sessionState> node
<sessionState> node for configuring the current asp.net application's session state configuration. The following is a common configuration:
<sessionStatecookieless="false"mode="InProc"timeout="30"/>

Above the node configuration is set in the asp.net application enabled Cookie, and specify the session state mode to save session state in the process, but also specifies the session timeout is 30 minutes.
<sessionState> node Mode attribute value can be one of the following:
Attribute Value Description
Custom use a custom data to store session state data.
InProc default. By the asp.net worker process to store session state data.
Off to disable session state.
SQLServer SQLServer database using the save-process session state data.
StateServer use-process ASP.NET state service to store state information.
By default, the general use InProc mode to store session state data, the benefits of this model is the access speed, memory for disadvantage Bijiao, it should not be large in this mode user session data storage.

<globalization> node:
Globalization used to configure the application settings. This node has a few more important attributes are as follows:
Property Name Description
fileEncoding optional attributes. Settings. Aspx,. Asmx and. Asax file storage encoding.
requestEncoding optional attributes. Client requests to set the encoding, default is UTF-8.
responseEncoding optional attributes. Set the server-side response to the encoding defaults to UTF-8.
The following is the asp.net application default configuration:
<globalizationfileEncoding="utf-8"requestEncoding="utf-8"responseEncoding="utf-8"/>

Although reading and writing the configuration file web.config file is an XML file, but due to the deployment of authority because it can not operate like a normal XML file, as modified, in the. Net provides a class for the conduct of the web.config changes.
The following are general categories for the web.config modify the code:
usingSystem;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Configuration;
/ / / <summary>
/ / / ConfigurationOperator's summary
///</ Summary>
publicclassConfigurationOperator: IDisposable
(
privateConfigurationconfig;
ConfigurationOperator () ConfigurationOperator (): this (HttpContext.Current.Request.ApplicationPath)
(

)
ConfigurationOperator () ConfigurationOperator (stringpath)
(
config = WebConfigurationManager.OpenWebConfiguration (path);
)
/ / / <summary>
/ / / Set the application configuration node, if this node already exists, it will modify the node's value, otherwise add this node
///</ Summary>
/ / / <paramname="key"> Node name </ param>
/ / / <paramname="value"> Node value </ param>
voidSetAppSetting () voidSetAppSetting (stringkey, stringvalue)
(
AppSettingsSectionappSetting = (AppSettingsSection) config.GetSection ("appSettings");
if (appSetting.Settings [key] == null) / / If this node does not exist, then add
(
appSetting.Settings.Add (key, value);
)
else / / if this node is modified
(
appSetting.Settings [key]. Value = value;
)
)
/ / / <summary>
/ / / Set the database connection string node, if this node does not exist, it will add this node and the corresponding value, there are changes
///</ Summary>
/ / / <paramname="key"> Node name </ param>
/ / / <paramname="value"> Node value </ param>
voidSetConnectionString () voidSetConnectionString (stringkey, stringconnectionString)
(
ConnectionStringsSectionconnectionSetting = (ConnectionStringsSection) config.GetSection ("connectionStrings");
if (connectionSetting.ConnectionStrings [key] == null) / / If this node does not exist, then add
(
ConnectionStringSettingsconnectionStringSettings = newConnectionStringSettings (key, connectionString);
connectionSetting.ConnectionStrings.Add (connectionStringSettings);
)
else / / if this node is modified
(
connectionSetting.ConnectionStrings [key]. ConnectionString = connectionString;
)
)
/ / / <summary>
/ / / Save the changes
///</ Summary>
voidSave () voidSave ()
(
config.Save ();
config = null;
)
voidDispose () voidDispose ()
(
if (config! = null)
(
config.Save ();
)
)
)

The above code stored in the App_Code folder, we can directly in the project use.
We demonstrate through an example using the generic class if set on the web.config. Create a new aspx page, the following code is the front:
<% @ PageLanguage = "C #" AutoEventWireup = "true" CodeFile = "ConfigModifyDemo.aspx.cs" Inherits = "ConfigModifyDemo"%>
<! DOCTYPEhtmlPUBLIC "- / / W3C / / DTDXHTML1.0Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title> modify web.config after deployment example </ title>
</ Head>
<body>
<formid="form1"runat="server">
<div>
<tableborder="0"cellpadding="0"cellspacing="0">
<tr> <td> type </ td> <td> Name </ td> <td> value </ td> </ tr>
<tr> <td>
Configuration </ td> <td>
<asp:TextBoxID="txtKey"runat="server"> </ asp: TextBox>
<Asp: RequiredFieldValidatorID = "RequiredFieldValidator2" runat = "server" ControlToValidate = "txtKey"
ErrorMessage = "*" Display = "Dynamic"> </ asp: RequiredFieldValidator> </ td> <td>
<asp:TextBoxID="txtAppSetting"runat="server"> </ asp: TextBox> </ td> </ tr>
<tr> <td>
Database Connection </ td> <td>
<asp:TextBoxID="txtConnectionName"runat="server"> </ asp: TextBox>
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ErrorMessage="*"ControlToValidate="txtConnectionName"Display="Dynamic"> </ asp: RequiredFieldValidator> </ td> <tdstyle="height:24px">
<asp:TextBoxID="txtConnectionString"runat="server"> </ asp: TextBox> </ td> </ tr>
<tr> <td>
<asp:ButtonID="btnModify"runat="server"OnClick="btnModify_Click"Text=" Modify "/> </ td> <td> </ td> <td> </ td> </ tr>
</ Table>
</ Div>
</ Form>
</ Body>
</ Html>
May be necessary to write code-behind to increase reading and writing class configuration file where the dll reference, as follows:
The following is background code:
usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingSystem.Web.Configuration; / / Note that this namespace to add
publicpartialclassConfigModifyDemo: System.Web.UI.Page
(
voidPage_Load () voidPage_Load (objectsender, EventArgse)
(
)
voidbtnModify_Click () voidbtnModify_Click (objectsender, EventArgse)
(
stringappSetting = txtAppSetting.Text; / / appSetting child node value
stringconnectionString = txtConnectionString.Text; / / connection string
stringkey = txtKey.Text; / / appSetting child node Key
stringconnectionName = txtConnectionName.Text; / / Connection Name
ConfigurationOperatorop = newConfigurationOperator ();
op.SetAppSetting (key, appSetting);
op.SetConnectionString (connectionName, connectionString);
op.Save ();
)

)

The following are the interfaces:
We fill in the form above the following information:
Assumptions related to the node at this time web.config file as follows:
<appSettings>
</ AppSettings>
<connectionStrings>
<addname="Conn"connectionString="DataSource=(local);InitialCatalog=AspNetStudy;PersistSecurityInfo=True;UserID=sa;Password=sa"/>
</ ConnectionStrings>
We click on "Edit" button in the file reads as follows:
<appSettings>
<addkey="country"value="china"/>
</ AppSettings>
<connectionStrings>
<Addname = "Conn" connectionString = "DataSource = (local); InitialCatalog = Study; UserID = sa; Password = sa"
providerName = "System.Data.SqlClient" />
</ ConnectionStrings>
The results can be seen from the implementation of our program really can do the modifications and additions web.config node function. Note that, in use after some version control software (such as MicrosoftVisualSourceSafe), version control software may be set to read-only attribute web.config, there will not be set, we need to manually to web.config of Remove the read-only attribute to set the web.config file. When the actual deployment of the project would not exist the problem.
Summary: web.config asp.net application is a very important configuration files, you can help us through the web.config file for development and deployment of asp.net application. In addition, the program can also control some flexibility. In this in detail the role of each node. Because after the deployment of asp.net application can not be because of permission in accordance with reason to modify web.config File XML approach, so in this also provides a node for <appSettings> node and set the general class <connectionStrings>, Readers can based on actual project need to be improved and the general class to add.
Next I will guide you into the internal asp.net, asp.net to know the internal operation mechanism, which is more flexible for us to control the asp.net application is very helpful.
2008-11-501:47
Duke of Zhou (Zhou Jinqiao)
Something more recent, very busy, and may make time will be longer, but Yehao have time for me to think about my presentation.

分类:DotNet 时间:2010-07-07 人气:555
分享到:
blog comments powered by Disqus

相关文章

  • linux file system configuration files 2011-06-10

    Blue file ---------- directory White paper ---------- General documents, such as text files, configuration files, source files, etc. ---------- Blue file link file, mainly documents created using the ln command Green ---------- executable files, exec

  • Understanding Linux configuration files 2010-09-29

    Introduction Every Linux program is an executable file that contains the opcode list, CPU will perform these operations to complete a specific operation code. For example, ls command from / bin / ls document, that document contains a list of machine

  • Getting Started with Tomcat configuration files 2010-03-29

    Tomcat basic configuration tomcat read the configuration file is the first mention briefly how to read the tomcat configuration file. tomcat on startup, first of all to find the system variable CATALINA_BASE, if not, then look for CATALINA_HOME. Then

  • Quick Edit Shell command line 2010-02-20

    This film article is true, make a backup, reproduced below: Author: robinswan From: LinuxSir.Org Abstract: For the Linux / Unix kernel obtained from the overall structure of such, to even the smallest of the small software application to the text to

  • Start the system with the grub command line 2010-06-02

    Start the system through the command line process: 1 root (hd0, 2) 2 kernel / vmlinuz-2.6.26.5-28.fc8 ro root = / dev/VolGroup00/LogVol00 rhgb quiet 3 initrd / initrd-2.6.26.5-28.fc8.img 4 boot Command Line 1: Specify / boot partition. (By Tab key, i

  • Advanced Course on the command line selection of CMD, eds (rpm) 2010-11-06

    Chapter I Section I often batch based on the internal command batch Introduction 1, REM, and:: 2, ECHO, and @ 3, PAUSE 4, ERRORLEVEL 5, TITLE 6, COLOR 7, mode configuration system equipment 8, GOTO and: 9, FIND 10, START 11, assoc and ftype 12, pushd

  • [Change] you do not know five things - JVM command line options 2010-09-02

    This is Ted Neward on IBM developerWorks in the 5 things in a series of articles , about the JVM command line parameters on some applications of tips worth learning. (2010.09.01 last update) Abstract: Java virtual machine with hundreds of command lin

  • Hibernate configuration files in the application of unit tests 2010-11-15

    Hibernate is a popular open source object-relational mapping tools, unit testing and the importance of continuous integration has also been widely promoted and recognized projects in the use of Hibernate, how to ensure the test automation and continu

  • FireBug Console - command line 2010-06-29

    Official Documents - Command line with the tab auto-complete feature All special function command line see the table below: Command Description $(id) Back by id Element. $$(selector) Back through the CSS selector Element Array . $x(xpath) Xpath expre

  • JAVA and JAVAC command line 2010-07-01

    javac, and java-classpath command line option in this is a very basic Wen Ti, Danshiyinwei Jiben Shang are with the existing IDE Gongju to develop java Program , so very few realize it. javac -Classpath, set the path to search for class and can be di

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.039 (s). 13 q(s)