Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Refernce Exception after encrypting web.config file using Data Protection API
    primarykey
    data
    text
    <p>I have encrypted the <strong>appSettings</strong> and <strong>connectionStrings</strong> section of the web.config file of my web application.</p> <p>These are the two commands that I entered at the Visual Studio 2010 command prompt:</p> <pre><code>aspnet_regiis.exe -pef "connectionStrings" C:\Provider -prov "DataProtectionConfigurationProvider" aspnet_regiis.exe -pef "appSettings" C:\Provider -prov "DataProtectionConfigurationProvider" </code></pre> <p>Now, these two commands produced a new web.config file situated in the directory along with the solution file. I opened this web.config file, which only contained the encrypted appSettings and connectionStrings section of the original web.config file.</p> <p>I then opened my web application, deleted the original <strong>appSettings</strong> and <strong>connectionStrings</strong> sections and pasted the encrypted ones.</p> <p>This is how my web.config file looks now:</p> <pre><code>&lt;configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt; &lt;appSettings configProtectionProvider="DataProtectionConfigurationProvider"&gt; &lt;EncryptedData&gt; &lt;CipherData&gt; &lt;CipherValue&gt;AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA6h2T0PWsHUC2CPpYvY8QUwQAAAACAAAAAAAQZgAAAAEAACAAAAAdlSIaGrQ1CFjswJi2RxekJ4ZxmRArilsOiqrmUXt6JgAAAAAOgAAAAAIAACAAAACaV/bVjlK60wX9LOFzRsrkbcDjSOT+3Qj0JyUZZszNNSAAAACaQC3oKCPX1gaxZK3ghS6lAMcVwpNpbMpyNpeoiwxap0AAAAD87rr8QUaIQJv2Sc+i+RGWq1+vExAPNjjG1VtWvK4ILsOX88iBRRx0tpAFdNAw0AvGoxUTA7UQGKm7hTHBaAMz&lt;/CipherValue&gt; &lt;/CipherData&gt; &lt;/EncryptedData&gt; &lt;/appSettings&gt; &lt;connectionStrings configProtectionProvider="DataProtectionConfigurationProvider"&gt; &lt;EncryptedData&gt; &lt;CipherData&gt; &lt;CipherValue&gt;AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA6h2T0PWsHUC2CPpYvY8QUwQAAAACAAAAAAAQZgAAAAEAACAAAAB4Y7QqEGRvo9T04hE8hvd3wMvRXqIMa/UJBkOQnMnsbgAAAAAOgAAAAAIAACAAAADnzwxmuoWUQLYJ0/YPUkgvR/xyXDZNaQI4ZrMmACqvaTAAAAC6C0nEhW+g8WHcNJLN5DRi8uNimkG3GyMEajrB33ST7DN49W925xIeMiN3kvyLAcJAAAAAPcgh+jh6RzsfQElj7/e1RNAQEFQykiqYfLbUEMd+qHcfkLCNwe3tczJQDckGH1cT7Y9At16pPfek1bKZeM7YpQ==&lt;/CipherValue&gt; &lt;/CipherData&gt; &lt;/EncryptedData&gt; &lt;/connectionStrings&gt; &lt;system.web&gt; &lt;compilation debug="true" explicit="true" targetFramework="4.0"/&gt; &lt;httpCookies httpOnlyCookies="true" requireSSL="true"/&gt; &lt;customErrors mode="On" defaultRedirect="DefaultErrorPage.htm"&gt; &lt;error statusCode="404" redirect="ErrorPage.htm"/&gt; &lt;/customErrors&gt; &lt;trace enabled="false"/&gt; &lt;/system.web&gt; &lt;/configuration&gt; </code></pre> <p>The problem that I have now is that when I try to use a page which accesses data in the web.config file (such as the connection string), I am getting a null reference exception.</p> <p>For instance, this line generates a null reference exception:</p> <pre><code>string connection = ConfigurationManager.ConnectionStrings["DB_Connection"].ConnectionString; </code></pre> <p>How can I solve this please? Thank you :)</p> <p><strong>Clarification</strong></p> <p>The line worked perfectly before encrypting using the Data Protection API. The null reference exception started cropping up after encryption.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload