Click here to Skip to main content
14,426,566 members
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,
Updated 15-Mar-10 21:43pm
Rate this:
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:
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)

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