<p>The DpapiDataProtectionProvider utilizes <a href="http://msdn.microsoft.com/en-us/library/ms995355.aspx">DPAPI</a> which will not work properly in a web farm/cloud environment since encrypted data can only be decrypted by the machine that encypted it. What you need is a way to encrypt data such that it can be decrypted by any machine in your environment. Unfortunately, <a href="http://ASP.NET">ASP.NET</a> Identity 2.0 does not include any other implementation of IProtectionProvider other than DpapiDataProtectionProvider. However, it’s not too difficult to roll your own.</p>
<p>One option is to utilize <a href="http://msdn.microsoft.com/en-us/library/system.web.security.machinekey(v=vs.110).aspx">the MachineKey class</a> as follows:</p>
<p>`public class MachineKeyProtectionProvider : IDataProtectionProvider<br>
{<br>
public IDataProtector Create(params string<span class="chcklst-box fa fa-square-o"></span> purposes)<br>
{<br>
return new MachineKeyDataProtector(purposes);<br>
}<br>
}</p>
<p>public class MachineKeyDataProtector : IDataProtector<br>
{<br>
private readonly string<span class="chcklst-box fa fa-square-o"></span> _purposes;</p>
<pre><code>public MachineKeyDataProtector(string[] purposes)
{
_purposes = purposes;
}
public byte[] Protect(byte[] userData)
{
return MachineKey.Protect(userData, _purposes);
}
public byte[] Unprotect(byte[] protectedData)
{
return MachineKey.Unprotect(protectedData, _purposes);
}
</code></pre>
<p>}</p>
<pre><code class="lang-auto">
In order to use this option, there are a couple of steps that you would need to follow.
Step 1
Modify your code to use the MachineKeyProtectionProvider.
</code></pre>
<p>using Microsoft.AspNet.Identity.Owin;<br>
// …</p>
<p>var provider = new MachineKeyProtectionProvider();<br>
UserManager.UserTokenProvider = new DataProtectorTokenProvider(<br>
provider.Create(“ResetPasswordPurpose”));</p>
<pre><code class="lang-auto">
Step 2
Synchronize the MachineKey value across all the machines in your web farm/cloud environment. This sounds scary, but it's the same step that we've performed countless times bef
(Réponse tronquée)</code></pre>