Error when encrypting web.config database connection string

The code below is supposed to encrypt the database connection string in web.config, however, when run it throws an error.  Can anyone shed any light on why such an error would occur??

Dim path as string = "/netdump"
Dim config as configuration = WebConfigurationManager.OpenWebConfiguration(path)
Dim appSettings as configurationSection = config.getSection("connectionStrings")
If order then
      appSettings.sectionInformation.protectSection("DataProtectionConfigurationProvider")
Else
      appSettings.sectionInformation.UnprotectSection()
End If
config.Save()

- Error ----------------------------------------
Unable to save config to file 'c:\inetpub\wwwroot\netdump\web.config'.
Line 22:  config.Save()
LVL 25
RouchieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RejojohnyCommented:
where r u running this code from .. the same machine where the web server resides? is the file set as "read only" ...
RouchieAuthor Commented:
The file isn't set as read only and it is on the same machine as the web server.  I've managed to work around the problem by setting the ASP.NET user account on the machine to have MODIFY access privileges to the file directly.  For some reason though, the FULL CONTROL box is ticked and also greyed out.  Not sure if this is an advisable way to proceed though from a security perspective.
RejojohnyCommented:
once u have run the code to encrypt the connectionstring .. u can reset the permission of the file .. i assume u do not need this feature in the production environment .. right?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RouchieAuthor Commented:
I guess not.  So if I encrypt locally on my development machine, and then copy web.config across to the server, the server will be able to read it okay?
RejojohnyCommented:
i assume it should work .. unless the encrypt logic uses some machine specific details .. u could give it a try ... haven't tried it myself ..

Rejo
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.