RHok
RHok

Reputation: 152

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). This all works fine.

My problem is reading even a simple string from 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:

<?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". If I change it to

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

it works perfectly.

This is driving me crazy.

Upvotes: 1

Views: 13175

Answers (3)

Umar Farooq Khawaja
Umar Farooq Khawaja

Reputation: 3987

ConfigurationManager is for dealing with app config files for assemblies, rather than for Web.config files. Please use WebConfigurationManager instead.

Upvotes: 0

Sean Barlow
Sean Barlow

Reputation: 588

have you tried double \'s in the config? Like "c:\\images\\new"

Upvotes: 0

Andrew Barber
Andrew Barber

Reputation: 40150

You should be using the WebConfigurationManager class instead of the ConfigurationManager. The interface on it is basically the same.

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

Upvotes: 8

Related Questions