Advertisements

Archive

Posts Tagged ‘Web.Config’

C# – Configuration section cannot be used at this path

January 22, 2019 Leave a comment

Other day , while accessing my WCF service (i.e., .svc) from IIS server, I was getting below error:

iis_3

Reason:

  • In my case, Issue is with missing ‘Write’ privilege for ‘Windows Authentication’ in IIS server.

Fix:

To fix the issue follow below steps

  • Connect to your IIS server
  • Select the ‘Server node’ (i.e., Your machine name) from left ‘Connections’ pane
  • On the right ‘Features View’ pane, select ‘Feature Delegation’ option

iis_1

  • From the list, select ‘Authentication – Windows’ option and make sure the delegation set to ‘Read\Write’
    • If its only ‘Read’, click on ‘Read/Write’ link from right side ‘Set Feature Delegation’ pane.

iis_2

  • Restart your web app
  • Try to browse the files and they should work now.

iis_4

🙂

 

Advertisements

“Bad Data” Error – During Web.Config file Decryption

February 15, 2016 Leave a comment

In one of my web application we are reading credentials from Web.config file’s Connection Strings section.

And we are encrypting the Connection Strings using aspnet_regiis.exe tool during deployments.

Below are the steps to Encrypt/Decryption of Config file using aspnet_regiis.exe tool

Encryption Command

  • Open Visual Studio Command Prompt and run below commands.

   Encrypt Connection Strings  > aspnet_regiis.exe -pef “connectionStrings” “<Path of folder containing web.config file>”

Encrypt App Settings  > aspnet_regiis.exe -pef “appSettings” “<Path of folder containing web.config file>”

  • Ex: If my web.config exists at wwwroot folder, below is the command to encrypt ‘connectionStrings’ section

     aspnet_regiis.exe -pef “connectionStrings” ” C:\inetpub\wwwroot\MyPublishedSite”

WebConfig - Path

WebConfig – Path

Encryption - config file

Encryption – config file

Decryption Command

   Decrypt Connection Strings > aspnet_regiis.exe -pdf “connectionStrings” “<Path of folder containing web.config file>”

Decrypt App Settings > aspnet_regiis.exe -pdf “appSettings” “<Path of folder containing web.config file>”

How to read the encrypted values in your code?

  • No need of any special statements in your code to the read the encrypted values.
  • Your “ConfigurationManager” will take care (i.e., ConfigurationManager.AppSettings[“mypassword”] will return the actual value even if its encrypted)

Key points about Encryption/Decryption

  • Encryption/Decryption is always specific to a machine.
  • So you cannot decrypt a file on Machine 2 which has been encrypted on Machine 1 and ‘aspnet_regiis’ tool throws “Bad Data” error, if you attempt.
Bad Data - Decrypting config file

Bad Data – Decrypting config file

Reason and Fix for the “Bad Data” error:

  • As mentioned earlier, Encryption/Decryption is always specific to a machine.
  • In my case, I tried to Decrypt a file which was encrypted in my Test server, from my Local machine which resulted a “Bad Data” error.
  • To fix the issue, I connected to “Test server” where the config file was originally encrypted, and decryption done successfully.

🙂

Categories: Misc Tags: , , ,