Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Win2008
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 15-Mar-10 21:14pm
Programm3r11.3K
Edited 15-Mar-10 21:43pm
v2
Rate this: bad
good
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.
 
Also,run:
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe
  Permalink  
v2
Rate this: bad
good
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,
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 295
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 16 Mar 2010
Copyright © CodeProject, 1999-2014
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