Click here to Skip to main content
15,898,222 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.Clear();
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);
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
webconfig.Save(System.Configuration.ConfigurationSaveMode.Modified);


Any pointers to why I am only receiving the error on Server 2008?
Many thanks in advance.
Kind regards,
Posted
Updated 15-Mar-10 20:43pm
v2

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.

Also,run:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe
 
Share this answer
 
v2
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