c# - ASMX 网络服务的配置文件

标签 c# web-services web-config asmx

所以我在 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/

相关文章:

c# - 空合并运算符是否有 "opposite"? (……用任何语言?)

java - 为什么我无法在 Web 服务 'Hello world' 示例中生成客户端代码?

asp.net - Visual Studio 2008 是否具有适用于 ASP.NET 的 Web.config.Debug 和 Web.Config.Release?

php - webservice接收参数数组作为字符串而不是数组

java - 如何提供自己的Web服务实现实例?

c# - 从 config 加载一些,从 configSource 加载一些

asp.net-mvc - 配置托管模块的 Asp.net MVC 错误

c# - ASP.NET Core 1 (RTM) 中的自定义 DateTime 模型绑定(bind)器

c# - 我可以强制 svcutil.exe 为 WCF 服务生成数据协定吗?

c# - MongoDB Norm 查询嵌套对象