in ASP. Net. config, the database connection string is encrypted and decrypted.
Although not very fresh, but believe that there are many people do not know, good, do not say nonsense, directly to the method: Start---> Run, enter cmd, and then enter the following content
Encryption:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe-pef "ConnectionStrings" "Your Web Project path"
Decrypt:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe-pdf "ConnectionStrings" "Your Web Project path"
. NET to modify the path of the version itself, where the name of the connectionstrings connection string.
Note that a native-based key is used in the encryption process, which means that the decryption process must be done on the same computer. If you move the encrypted Web. config file to another computer, the connection string in the Web. config file will not be decrypted properly.
The asp.net2.0 provides a simple encryption method that uses the Aspnet_iis.exe command, which is located in the following order:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
Note that the system location and version number vary depending on the situation
Enter the directory in command mode to run, and the complete command is:
Aspnet_iis-pef "ConnectionStrings" "web.cofing Absolute Path (note: No need to enter Web. config)"
If "Success" is normally prompted, opening Web. config will find that the string is encrypted
The decryption command is:
Aspnet_iis-pdf "ConnectionStrings" "web.cofing Absolute Path (note: No need to enter Web. config)"
Note that encryption and decryption must be done on a single machine.
-----------------------------
The following shows the code to encrypt the database connection string, as follows:
Configuration config = webconfigurationmanager.openwebconfiguration (request.applicationpath);
ConfigurationSection configsection = config. GetSection ("connectionStrings");
if (configSection.SectionInformation.IsProtected)
... {//If it is already encrypted, no more encryption is necessary.
ConfigSection.SectionInformation.UnprotectSection ();
Config. Save ();
}
Else
... {
ConfigSection.SectionInformation.ProtectSection ("DataProtectionConfigurationProvider");
Config. Save ();
}