Error when encrypting web.config database connection string

Posted on 2006-03-22
Last Modified: 2012-05-05
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
End If

- Error ----------------------------------------
Unable to save config to file 'c:\inetpub\wwwroot\netdump\web.config'.
Line 22:  config.Save()
Question by:Rouchie
    LVL 26

    Expert Comment

    where r u running this code from .. the same machine where the web server resides? is the file set as "read only" ...
    LVL 25

    Author Comment

    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.
    LVL 26

    Accepted Solution

    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?
    LVL 25

    Author Comment

    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?
    LVL 26

    Expert Comment

    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 ..


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now