[转] Development Break Realization Web.config

xiaoxiao2021-04-04  232

In Web development, configuring Web.cofig is unqualified by non-technical personnel, but often needs to be simply configured by customers, need to provide a valid tool to guide customers to complete this operation, and prevent invalidation or errors Change.

solution:

First, you must understand the configuration of the system mainly includes two parts of Machine.config and Web.config. These two files are inherently an XML file, which contains all configuration information for ASP.NET. Therefore, the configuration of the system is actually the operation of the XML file, so we can take the read and write operations for the XML file to achieve quick configuration. Here we mainly describe the contents of each data item in the web.config, which is not discussed by Web.Config, and the specific content can be referred to in the description of the MSDN.

The core code of the realization is:

Private void btnok_click (Object Sender, System.EventArgs E)

{

/ / Define variables

String strlocation = txtLocation.text;

String strprovider = txtProvider.Text;

String strmode = txtmode.text;

String struser = txtuser.text;

String strdataserce = txtdataserce.text;

String strpwd = txtpwd.text;

String semicolon = ";";

// Operate the XML node

XMLDocument Xmldoc = new xmldocument ();

XMLDoc.Load ("MyXML.xml");

XMLNode XNode = Xmldoc.selectsinglenode ("// Appsettings / Add [@ key = 'oledbconnection1.connectionstring']");

IF (XNode! = NULL)

{

Xnode.attributes ["value"]. value = "location =" strlocation semicolon "provider =" STRPROVIDER SEMICOLON

"Mode =" STRMODE SEMICOLON "User ID =" Struser SEMICOLON "Data Source =" STRDATASOURCE SEMICOLON

"Password =" strPwd;

}

XMLDoc.save ("MyXML.XML");

Messagebox.show ("Set success!");

}

In the code, we take MYXML.XML as an example to represent any other XML modifications.

These are just a simple data item operation, and further operation needs to continue to be improved.

On the following operation interface, non-technical personnel can make it easy to modify the information.

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

New Post(0)