所以我在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";
效果很好。
这让我发疯了。
答案 0 :(得分:7)
您应该使用WebConfigurationManager类而不是ConfigurationManager
。它上面的界面基本相同。
string notFrom =
System.Web.Configuration.WebConfigurationManager.AppSettings["folder_new"];
答案 1 :(得分:0)
你在配置中尝试过双击吗?与"c:\\images\\new"
答案 2 :(得分:0)
ConfigurationManager
用于处理程序集的app配置文件,而不是Web.config文件。请改用WebConfigurationManager
。