1

所以我在 Visual Studio 2010 中创建了一个 Web 服务。要将其部署到 IIS Web 服务器上,我将 service.asmx、web.config 和 bin 复制到服务器(wwwroot 文件夹)。这一切都很好。

我的问题是从 web.config 中读取一个简单的字符串。我的代码是:

在一种方法中,我有:

string from = System.Configuration.ConfigurationManager.AppSettings["folder_new"];

在 web.config 文件中,我有:

<?xml version="1.0"?>
<configuration>    
  <appSettings>
    <add key="folder_new" value="C:\images\new" />
  </appSettings>
  <...other stuff etc...>
</configuration>

我从“从”位置读入。如果我将其更改为

string from = @"C:\images\new";

它完美地工作。

这真让我抓狂。

4

3 回答 3

8

您应该使用WebConfigurationManager类而不是ConfigurationManager. 上面的界面基本一样。

string notFrom =  
  System.Web.Configuration.WebConfigurationManager.AppSettings["folder_new"];
于 2013-02-13T22:28:54.137 回答
0

你在配置中尝试过双\'s吗?像"c:\\images\\new"

于 2013-02-13T22:29:13.450 回答
0

ConfigurationManager用于处理程序集的应用程序配置文件,而不是 Web.config 文件。请WebConfigurationManager改用。

于 2013-02-13T22:34:36.420 回答