Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to decrypt a connectionString in a web.config using regiis_asp.net?

Tags:

asp.net

iis

I have tried using this command in cmd but it didn't work

c:/path.../regiis_asp.net -pi "connectionString" -app "d:/myWebSiteApp" 

the result of that command was

the configuration section "connectionString" was not found
failed
like image 850
more 2 know Avatar asked Nov 09 '11 11:11

more 2 know


People also ask

How do I decrypt a web config section?

Decrypting a Web Configuration Section To decrypt encrypted configuration file contents, you use the Aspnet_regiis.exe tool with the -pd switch and the name of the configuration element to be decrypted. Use the –app and -site switches to identify the application for which the Web. config file will be decrypted.

How do you read ConnectionString from configuration file into code behind?

To read the connection string into your code, use the ConfigurationManager class. string connStr = ConfigurationManager. ConnectionStrings["myConnectionString"].


2 Answers

Have you tried it this way?:

Encrypt:

aspnet_regiis.exe -pef "connectionStrings" C:\path\to\application

Decrypt:

aspnet_regiis.exe -pdf "connectionStrings" C:\path\to\application
like image 57
James Johnson Avatar answered Oct 06 '22 09:10

James Johnson


If your intention is to decrypt the connectionStrings section in the web.config, you will have to use the below command.

aspnet_regiis -pdf "connectionStrings" -app "d:/MyWebsiteApp"

Note: in the code provided by you, please note the following

1) the utility command is aspnet_regiis instead of regiis_asp.net

2) Since your app is referred from the physical path, the container configuration must be -pdf instead of -pi

3) The section name is connectionStrings instead of connectionString ( notice the 's')

If you are trying to decrypt from the virtual path then the command must be as below

aspnet_regiis -pd "connectionStrings" -app "/MyWebsiteApp"
like image 34
clklachu Avatar answered Oct 06 '22 09:10

clklachu