In most cases some sections of the web.config file of an ASP.NET project need to be encrypted before moving project to a production server. The most important section to encrypt is the connectionString, because of the login information it contains. Here is a quick way to encrypt the sections you want, without adding or changing your code.

The sections that may contain sensitive information are the appSettings, connectionStrings, identity and sessionState. For this example I will encrypt the appSettings and connectionsStrings sections. Here are the 2 sections before encryption:

    <appSettings>
        <add key="valueOne" value="Hello, World!">
        <add key="valueTwo" value="http://amgadhs.com">
    </appSettings>

    <connectionStrings>
        <add name="amgadhsConnectionString"
          connectionString="Data Source=.;Initial Catalog=AmgadHS;Integrated Security=True"
          providerName="System.Data.SqlClient">
    </connectionStrings>

To encrypt them start the Command Prompt from the shortcut in the Visual Studio folder in the Start menu. This Command Prompt starts with the Visual Studio binary folders added to the path, which makes running the command from project's folder easier. So change to the project's folder and run the following 2 commands:

aspnet_regiis -pef "connectionStrings" . -prov "DataProtectionConfigurationProvider"

aspnet_regiis -pef "appSettings" . -prov "DataProtectionConfigurationProvider"

The first one encrypts the connectionString section and the second encrypts the appSettings section. The DataProtectionConfigurationProvider provider uses Data Protection API (DPAPI) to encrypt the sections. The result is the following:

    <appSettings configProtectionProvider="DataProtectionConfigurationProvider">
        <EncryptedData>
            <CipherData>
                <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA7RqwTSkZT06NoXjc8dbudQQAAAACAAAAAAADZgAAqAAAABAAAAAjEnmSA+txghg3XCZ0/Rz6AAAAAASAAACgAAAAEAAAAEWe1xvZRhpbEgDArvzEk/YQAQAALfdlSbHw5ZKs0TNn6EiWJhlVvm+F++x4nWIfr/k+h/+L3ObNf2mWfNkvkq1iPyVq/rE08Chs8M11pfLdDpWsBvH+m+2ZC/tLseM+mbGiQQTg8P+NyNlwU17sAKftPV9hdrzteL/4ue3R2aYXGokrXhu3iSjvS3Hr65rXiH/umbb/IJ4I97vkv/yF8i7d/5Mv28iC+0qH7eLlR/SoXs34G2FYHyTPavuUvsAAjpLkzR+PRnwzrsxuYzjqtp3TZG2vqKJd5Fk560+o1OHsS+MsMFpQNmd24iUvgFoseB0zY5M/oLAWp87HMO8TAFyM5gGD3MDKaDXufdDwY4BrVtKDQeDiEK6osJeQAlQUIyRtN84UAAAAtzCrFSnDU6WvpR3S2UW5Uo1W0ss=</CipherValue>
            </CipherData>
        </EncryptedData>
    </appSettings>

    <connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
        <EncryptedData>
            <CipherData>
                <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA7RqwTSkZT06NoXjc8dbudQQAAAACAAAAAAADZgAAqAAAABAAAACV4L/jCXzOO4DLCam0klfgAAAAAASAAACgAAAAEAAAAHX5Nk9yhof/Cfv924MmKobAAQAAfkjan3JlVnH/X1eiFaiKwyYeVOhUX5BaNtC/vr2uIDSLpIB254Utf6onYMma0Uai/QRNtkCbXCdWQ+dujVQPN8fwmI6+MLtntlId2hy4fXi0kfA56XB5XU8+108yCsGSohLLyj4aYjuZuLsXZCP7+rfq8dphQtwKNGGglar6wR3ylt7kf4Vt5pEMB01C7thZi5+Ft1lptPaJVZfJZjpc2Afs8EGfK7S2NRkIXTj5oXArENVoi3Z7Iz93kIMKW0EFWRvjl56lvdEUeWGZM9cRYOW4Xf3TpeEEz5x61ggssJScmVMICnzs1qh4cnQF+oaMHZGDZZEA+sKdblo/DDe+EUPOTh59PnkbBaVzlF6pzULNdxt2bpoka3NpDg3tidfCtSej6eLUH4kYDjlZ6dyjOBO/BGE9lznQlGrkAIHNBECvIfuH7WwMlfvalh2Xm2o7NOVO9dCua3h+M5buyTVbzaps9/getRUJku/Mb71hJOtXKDFz/wGXolJfocMQAXwev7zY2bC9Wy+nj5stEWF/r/odDk0qgPEITrN5PjWdwvDgS8veZBn365o/SgZhaPLLMOl5MJ6/NUN4M0Asg5PzIRQAAADJ7VqJStI6O6zGIbRtDHE9mkMKww==</CipherValue>
            </CipherData>
        </EncryptedData>
    </connectionStrings>