Encrypting web.config failed error


I know that ppl have already asked questions regarding encrypting web.config.

im also trying to encrypt my test config file, but im getting this error.

aspnet_regiis -pef "connectionStrings" "C:\encryptedWeb.config"
Encrypting configuration section…
The configuration for physical path 'C:\EncryptedWeb.config' cannot be opened.

I just want to know, what could be reasons that it failed.

I got the answer, it was the readonly property of the web.config which was the problem.
After I removed the readonly It worked like a charm.

Best Solution

for the command "aspnet_regiis -pef" the path of configuration file is the physical path (Not virtual) and also it is the path of directory/folder where web.config resides. So one should not include the name of file in path e.g.

if your web.config path is at D:\MyConfiguration\web.config then while encrypting/decrypting you will use it as follow:


aspnet_regiis -pef [sectionName] "D:\MyConfiguration"


aspnet_regiis -pdf [sectionName] "D:\MyConfiguration"