读取Web.config的源码(C#.net 2005)
来源:互联网 发布:mac系统怎么打开终端 编辑:程序博客网 时间:2024/06/04 17:53
1:读取过程
public void ApplyConnectionInfo() {
string strConnection = string.Empty;
doc.Load(this.openFileName);
foreach (XmlNode node in doc["configuration"]["connectionStrings"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["name"].Value == "connectionString") {
strConnection = node.Attributes["connectionString"].Value;
}
}
}
string[] ConnInfo = strConnection.Split(';');
for (int i = 0; i < ConnInfo.Length; i++) {
string strTemp = ConnInfo[i].Trim();
if (strTemp.Length == 0) continue;
string Perfix = strTemp.Substring(0, strTemp.IndexOf("="));
if(Perfix.ToUpper().Equals("SERVER")) this.serverName = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("DATABASE")) this.database = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("UID")) this.userName = strTemp.Substring(strTemp.IndexOf("=") + 1);
if (Perfix.ToUpper().Equals("PWD")) this.password = strTemp.Substring(strTemp.IndexOf("=") + 1);
}
foreach (XmlNode node in doc["configuration"]["appParams"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["key"].Value == "remoteHostString") {
this.remoteIP = node.Attributes["value"].Value;
}
}
}
foreach (XmlNode node in doc["configuration"]["system.web"].ChildNodes) {
if (node.Name == "identity") {
this.SNuserName = node.Attributes["userName"].Value;
this.SNpassword = node.Attributes["password"].Value;
}
}
}
2:修改并保存
public void SaveConnectionInfo() {
try {
string strConnectionstring = String.Format("Server={0};Database={1};uid={2};pwd={3}", this.ServerName, this.DataBaseName, this.UserID, this.UserPassword);
doc.Load(this.OpenPath);
foreach (XmlNode node in doc["configuration"]["connectionStrings"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["name"].Value == "connectionString") {
node.Attributes["connectionString"].Value = strConnectionstring;
}
}
}
foreach (XmlNode node in doc["configuration"]["appParams"].ChildNodes) {
if (node.Name == "add") {
if (node.Attributes["key"].Value == "remoteHostString") {
node.Attributes["value"].Value = this.RemoteIP;
}
if (node.Attributes["key"].Value == "connectionString") {
node.Attributes["value"].Value = strConnectionstring;
}
}
}
foreach (XmlNode node in doc["configuration"]["system.web"].ChildNodes) {
if (node.Name == "identity") {
node.Attributes["userName"].Value=this.SNuserName ;
node.Attributes["password"].Value=this.SNpassword ;
}
}
System.IO.File.SetAttributes(this.openFileName, System.IO.FileAttributes.Normal);
doc.Save(this.openFileName);
System.IO.File.SetAttributes(this.openFileName, System.IO.FileAttributes.ReadOnly);
MessageBox.Show("PMFE web confirg file setting is saved!");
} catch (Exception e) {
MessageBox.Show("Error,Save is faile!");
}
}
3:'Web.confirg文件
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="uipConfiguration" type="Microsoft.ApplicationBlocks.UIProcess.UIPConfigHandler,Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" />
<section name="appParams" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<uipConfiguration enableStateCache="true" allowBackButton="false">
<objectTypes>
<iViewManager name="WebFormViewManager" type="Microsoft.ApplicationBlocks.UIProcess.WebFormViewManager, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" default="true" />
<state name="State" type="Microsoft.ApplicationBlocks.UIProcess.State, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" default="true" />
<controller name="WelcomeController" type="PMFE.UI.Component.Common.WelcomeController,PMFE.UI.Component, Version=1.0.0.0,Culture=neutral,PublicKeyToken=null" />
<statePersistenceProvider name="MemoryPersistState" type="Microsoft.ApplicationBlocks.UIProcess.MemoryStatePersistence, Microsoft.ApplicationBlocks.UIProcess, Version=1.0.1.0,Culture=neutral,PublicKeyToken=null" connectionString="server=.;database=UIPState;uid=rpms;pwd=rpms" default="true" />
</objectTypes>
<views>
<view name="WELCOME" type="Welcome.aspx" controller="WelcomeController" />
</views>
</uipConfiguration>
<system.web>
<identity impersonate="true" userName="Angel Wong" password="axio55" />
<compilation defaultLanguage="c#" debug="true">
<assemblies>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="Infragistics2.WebUI.Shared.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" />
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.ReportSource, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Shared, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304" />
<add assembly="Infragistics2.WebUI.UltraWebGrid.ExcelExport.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB" />
<add assembly="Infragistics2.Excel.v5.3, Version=5.3.20053.73, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB" />
</assemblies>
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" extension=".cs" compilerOptions="/d:DEBUG;TRACE" />
</compilers>
</compilation>
<customErrors mode="RemoteOnly" />
<authentication mode="None" />
<!--<identity impersonate="true" userName="*" password="*" />-->
<!--<authorization>
<deny users="?" />
</authorization>-->
<trace enabled="false" requestLimit="10" pageOutput="true" traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" cookieless="false" timeout="10" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
<xhtmlConformance mode="Legacy" />
<pages />
</system.web>
<appParams>
<add key="connectionString" value="Server=Server06;Database=PMFE;uid=*;pwd=*" />
<add key="remoteHostString" value="192.168.170.99" />
</appParams>
<connectionStrings>
<add name="connectionString" connectionString="Server=Server06;Database=PMFE;uid=*;pwd=*" providerName="System.Data.SqlClient" />
</connectionStrings>
<location path="en">
<system.web>
<globalization culture="en" uiCulture="en" />
</system.web>
</location>
</configuration>
- 读取Web.config的源码(C#.net 2005)
- .net 读取web.config中单个节点的方法
- Asp.net中读取web.config参数的方法
- ASP.Net 2.0的Web.config配置和读取
- ASP.NET读取web.config中单个节点的方法
- ASP.Net 2.0的Web.config配置和读取
- asp.net读取Web.config的<appSettings></appSettings>
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- Asp.net Web.config配置文件读取。
- .NET工程读取web.config或app.config中的appsettings时的注意事项
- .net下的web.config
- ASP.NET的web.config
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
- C#/ASP.NET应用程序配置文件app.config/web.config的增、删、改操作
- 8088 汇编指令速查
- 处理可预料的异常处理
- 大数运算(六)
- Datalist的三层嵌套
- Windows完成端口编程
- 读取Web.config的源码(C#.net 2005)
- Hibernate学习(3)----JDBC编程
- Winsock完成端口模型-Delphi代码
- AspectJ类名称模式
- 由于项目原因又用到了以前没接触到的东东(JAVACC,ASTParser,Java Development Tooling (JDT) )
- Object DataBase --DB4O之旅(1)
- 如何使用Delphi设计强大的服务器程序
- 完成端口深入理解
- 五﹑博客周刊•推荐Blog圈子