我写了一个程序,想在c#中读取Web.config文件中的字段,怎么读不出来,高手指点一下呀!
主程序是:
using System;
using System.Collections.Specialized;
using System.Configuration;
namespace test2
{
class test2
{
static void Main(string[] args)
{
string m_connString;
bool m_usePlainTextDbCxnString;
ConfigurationSettings.GetConfig ("Web.config");
m_usePlainTextDbCxnString = Convert.ToBoolean(ConfigurationSettings.AppSettings["sqlConn.UsePlainText"]);
if (m_usePlainTextDbCxnString)
{
m_connString = ConfigurationSettings.AppSettings["sqlConn.ConnectionString.PlainText"];
Console.WriteLine (m_connString);
Console.WriteLine ("one Ok ");
}
else
{
string cxnStringCipherText = ConfigurationSettings.AppSettings["sqlConn.ConnectionString.Protected"];
Console.WriteLine(cxnStringCipherText);
Console.WriteLine("two Ok");
}
}
}
}
Web.config文件是:
<configuration>
<appSettings>
<add key="sqlConn.ConnectionString.PlainText" value="workstation id='01';packet size=4096;user id=IVUser;integrated security=SSPI;data source='01';persist security info=False;initial catalog=IssueVision" />
<add key="sqlConn.ConnectionString.Protected" value="workstation id='01';packet size=4096;user id=IVUser;integrated security=SSPI;data source='01';persist security info=False;initial catalog=IssueVision" />
<add key="sqlConn.UsePlainText" value="false" />
</appSettings>
</configuration>
[此贴子已经被作者于2006-3-24 22:24:53编辑过]