Problem description:
There is a primary domain name extension 2.0 technology implementation, and distributed on different servers, now requires that the implementation of single point of login in these systems.
The method is as follows:
Add the following two nodes to the Web. config file of each site (subsystem ):
<System. Web>
<Machinekey validationkey = "machinekey"
Decryptionkey = "5f1c24d664a14ab7862fce8f6a98e9e274dc1e21e6bfb060"
Validation = "sha1"/>
<Authentication mode = "forms">
<Forms domain = ".wow52.cn"
Defaulturl = "index.html"
Name = ". XXX. comusernamecookie"
Protection = "all"
Loginurl = "/userlogin. aspx"/>
</Authentication>
</System. Web>
Used to generate a node <machinekey>CodeAs follows:
Using system;
Using system. text;
Using system. Security. cryptography;
Namespace crypto
{
Public class keycreator
{
Public static void main (string [] ARGs)
{
String [] commandlineargs = system. environment. getcommandlineargs ();
String decryptionkey = createkey (system. Convert. toint32 (commandlineargs [1]);
String validationkey = createkey (system. Convert. toint32 (commandlineargs [2]);
Console. writeline ("<machinekey validationkey = \" {0} \ "decryptionkey = \" {1} \ "validation = \" sha1 \ "/>", validationkey, decryptionkey );
}
Static string createkey (INT numbytes)
{
Rngcryptoserviceprovider RNG = new rngcryptoserviceprovider ();
Byte [] buff = new byte [numbytes];
RNG. getbytes (buff );
Return bytestohexstring (buff );
}
Static string bytestohexstring (byte [] bytes)
{
Stringbuilder hexstring = new stringbuilder (64 );
for (INT counter = 0; counter {< br> hexstring. append (string. format ("{0: X2}", bytes [Counter]);
}< br> return hexstring. tostring ();
}< BR >}< br> compile the above Code to obtain the hashconfigcs.exe file
enter hashconfigcs.exe 24 64 key.txt
the content of the key.txt file is node
Note:
The Forms authentication in Asp.net is based on cookies.AlgorithmEncryption and signature are performed. By default, machine is used. in the config file, the <machinekey> node configuration information (key, and algorithm) is completed. <machinekey> in config usesAutogenerateThe keys on different servers are basically different, so you must manually specify them.