【发布时间】:2016-02-17 21:12:35
【问题描述】:
我有两个项目 1)没有接口的类库只是一个api 2) 网络应用
我将通过网络应用调用类库 api
所以我在 Web 应用程序中有所有 web.config 设置,但是当我调试它时总是返回空值,这里是代码片段:
public static string readingDB
{
get
{
string result = null;
result = ConfigurationManager.AppSettings["employeeDB"]; //conn string
if (!string.IsNullOrEmpty(result))
{
return result;
}
else
{
return ""; //???? THROW EXCEPTION???
}
}
}
我也尝试过,在类库项目中创建一个新的 app.config 并在那里具有相同的 appsettings 但不起作用...
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<applicationSettings>
<add name="employeeDB" connectionString="Data Source=servername;Initial Catalog=employee;Persist Security Info=True;User ID=userid;Password=password;"/>
</applicationSettings>
<customErrors mode="On"/>
</configuration>
有什么帮助吗?
【问题讨论】:
标签: asp.net web-config app-config