Reputation: 29036
I am Trying to get the configuration file using the following code:
public void EncryptConnString()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Server.MapPath(@"/"));
ConfigurationSection section = config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
{
config.Save(ConfigurationSaveMode.Modified);
}
}
But i am getting the error
The relative virtual path 'F:/xxxx/yyyy/sample/' is not allowed here.
Note: I am accessing this code in global.asax
page What i am doing wrong?
Upvotes: 1
Views: 5613
Reputation: 98
If you pass null to this method, it will return the root config file for you:
var config = WebConfigurationManager.OpenWebConfiguration(null);
Upvotes: 3