所以我在 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>
我从“from”位置读入。如果我把它改成
string from = @"C:\images\new";
它完美地工作。
这让我发疯。
最佳答案
您应该使用 WebConfigurationManager类而不是 ConfigurationManager
。上面的界面基本一样。
string notFrom =
System.Web.Configuration.WebConfigurationManager.AppSettings["folder_new"];
关于c# - ASMX 网络服务的配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14864399/