Here is my c# code :
System.Configuration.Configuration config =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/Web.config");
ConfigurationSection section = config.GetSection("app开发者_如何学GoSettings");
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Modified);
string sectionXml = section.SectionInformation.GetRawXml();
I need to encrypt web.config
programatically, but it gives me error:
A configuration file cannot be created for the requested Configuration object.
The error is on the ~/web.config
, the OpenWebConfiguration
needs the full application path, not the name of the web.config as appears on web.
Try this (tested and working for the opening):
OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
or (base on msdn sample code)
OpenWebConfiguration(/web.config);
or even call it with null, as MSDN notes.
精彩评论