1, open Notepad, and then copy the following code into a new file.
Copy Code code as follows:
<%@ Page language= "C #"%>
<%
Response.Write (System.Security.Principal.WindowsIdentity.GetCurrent (). Name);
%>
Save My.aspx to your Web directory and run the form to display "NT authority\network SERVICE". Success!
2, (Key step) run CMD, execute the following
Aspnet_regiis-pa "NetFrameworkConfigurationKey" "NT authority\network SERVICE"
Description: Registers the default RsaProtectedConfigurationProvider RSA key container,
NetFrameworkConfigurationKey is the default provider for RsaProtectedConfigurationProvider. Success!
3, now, you can encrypt web.config, run:
Encryption: Aspnet_regiis-pe "connectionstrings"-app "/myweb"
Description: "ConnectionStrings" is the section to encrypt, "/myweb" is the web directory
Decryption: ASPNET_REGIIS-PD "connectionstrings"-app "/myweb"
Success!
4, so you can call in the program (do not decrypt, haha
):
...
String connstr= configurationmanager.connectionstrings["Myconnstr"]. Connectionstring.tostring ();
...
Similarly, you can create your own RSA key container, as follows:
(1), create "MyKeys" Key container, run: aspnet_regiis-pc "MyKeys"-exp
(2), add the following in Web.config:
Copy Code code as follows:
<protectedData>
<providers>
<add name= "MyProvider"
Type= "System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, version=2.0. 0.0,
Culture=neutral, PUBLICKEYTOKEN=B03F5F7F11D0A3A,
Processorarchitecture=msil "
Keycontainername= "MyKeys"
Usemachinecontainer= "true"/>
</providers>
</protectedData>
Save.
(3), grant the account access to the computer-level "MyKeys" RSA key container, and run:
Aspnet_regiis-pa "MyKeys" "NT authority\network SERVICE"
(4), now, can encrypt web.config, run:
Encryption: Aspnet_regiis-pe "connectionstrings"-app "/myweb"-prov "MyProvider"
Description: "connectionstrings" is the section to be encrypted, "/ Myweb "Yes Web directory," MyProvider "own key container
decryption: ASPNET_REGIIS-PD" connectionstrings "-app"/myweb "-prov" MyProvider "