简体   繁体   English

ASMX Web服务的配置文件

[英]config file for ASMX web service

So I have made a web service in Visual Studio 2010. To deploy it onto the IIS web server, I copy the service.asmx, web.config, and the bin over to the server (wwwroot folder). 因此,我在Visual Studio 2010中制作了一个Web服务。要将其部署到IIS Web服务器上,我将service.asmx,web.config和bin复制到服务器(wwwroot文件夹)上。 This all works fine. 这一切都很好。

My problem is reading even a simple string from web.config. 我的问题是甚至从web.config中读取一个简单的字符串。 My code is: 我的代码是:

In a method, I have: 在一种方法中,我有:

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

In the web.config file, I have: 在web.config文件中,我有:

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

I read in from the location "from". 我从“ from”位置读入。 If I change it to 如果我将其更改为

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

it works perfectly. 它完美地工作。

This is driving me crazy. 这真让我抓狂。

You should be using the WebConfigurationManager class instead of the ConfigurationManager . 您应该使用WebConfigurationManager类而不是ConfigurationManager The interface on it is basically the same. 它的接口基本相同。

string notFrom =  
  System.Web.Configuration.WebConfigurationManager.AppSettings["folder_new"];

have you tried double \\'s in the config? 您是否尝试过在配置中使用双\\? Like "c:\\\\images\\\\new" 就像"c:\\\\images\\\\new"

ConfigurationManager is for dealing with app config files for assemblies, rather than for Web.config files. ConfigurationManager用于处理程序集的应用程序配置文件,而不是Web.config文件。 Please use WebConfigurationManager instead. 请改用WebConfigurationManager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM