Archive
C# – Configuration section cannot be used at this path
Other day , while accessing my WCF service (i.e., .svc) from IIS server, I was getting below error:
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
- 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.
- Restart your web app
- Try to browse the files and they should work now.
đ
âBad Dataâ Error – During Web.Config file Decryption
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”
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.
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.
đ