Click here to Skip to main content
13,043,491 members (53,511 online)
Rate this:
Please Sign up or sign in to vote.
Hi all,

I am trying to encrypt my web.config file from an external application. The strange thing is that the application works on my Windows 7 PC as well as Server 2003, but I keep receiving the following error on Server 2008: Configuration file cannot be created for the requested configuration object. Here is the code that I am making use of:

System.Configuration.Configuration webconfig = WebConfigurationManager.OpenWebConfiguration("/WebService1") as System.Configuration.Configuration;
webconfig.ConnectionStrings.ConnectionStrings.Add(new System.Configuration.ConnectionStringSettings("connection",
	string.Format("Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}", item.DataSource, item.InitialCatelog, item.Username, item.Password)));
System.Configuration.ConfigurationSection section = webconfig.GetSection(webconfig.ConnectionStrings.SectionInformation.SectionName);

Any pointers to why I am only receiving the error on Server 2008?
Many thanks in advance.
Kind regards,
Posted 15-Mar-10 20:14pm
Updated 15-Mar-10 20:43pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Looks like an access permission issue. Verify you had given permissions to IIS if hosted or ASP.NET to access the file and modify it.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Well turns out that the issue was caused by an incorrect virtual path and website name.

Fix the parameters in the ctor of the OpenWebConfiguration and everything worked.
Thanks for the responses.

Kind regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Mar 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100