Click here to Skip to main content
15,441,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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,
Updated 15-Mar-10 20:43pm

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.

Share this answer
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,
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900