title: Generating reset password token does not work in Azure Website
body: <p>I am implementing reset password functionality on my site by using the in-built <code>UserManager</code> class that comes with ASP.NET 5.</p>
  
  <p>Everything works fine in my dev environment. However, once I try it in the production site that is running as an Azure website, I get the following exception:</p>
  
  <blockquote>
    <p><strong>System.Security.Cryptography.CryptographicException</strong>: The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context, which may be the case when the thread is impersonating.</p>
  </blockquote>
  
  <p>This is how I setup the <code>UserManager</code> instance:</p>
  
  <pre><code>var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider(SiteConfig.SiteName);
  UserManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider&lt;User&gt;(provider.Create(ResetPasswordPurpose));
  </code></pre>
  
  <p>Then, I generate the token thusly (to be sent to the user in an email so that they can verify that they do indeed want to reset their password):</p>
  
  <pre><code>string token = UserManager.GeneratePasswordResetToken(user.Id);
  </code></pre>
  
  <p>Unfortunately, when this runs on Azure, I get the exception above.</p>
  
  <p>I've Googled around and found this <a href="http://brockallen.com/2013/02/18/configuring-machine-key-protection-of-session-tokens-in-wif-and-thinktecture-identitymodel/" rel="noreferrer">possible solution</a>. However, it didn't work at all and I still get the same exception.</p>
  
  <p>According to the link, it has something to do with session tokens not working on a web farm like Azure.</p>