title: Windows Azure: web application on several instances, authentication?
body: <p>An existing web application I want to migrate to the Windows Azure Cloud authenticates users the following way somewhere in the (post)authenticaterequest event:</p>
  
  <pre><code>IPrincipal current = Thread.CurrentPrincipal;
  if (current != null &amp;&amp; ((IClaimsIdentity)current.Identity).Claims.Count &gt; 0)
  {
      IPrincipal result =  AuthManager.CreateGenericPrincipal(current.Identity);
      HttpContext.Current.User = result;
      Thread.CurrentPrincipal = result;
  }
  </code></pre>
  
  <p>The CreateGenericPrincipal method looks up roles in a xml file for the claimsidentity and creates a new GenericPrincipal with that roles. 
  Pages that need authentication just perform</p>
  
  <pre><code>IPrincipal p = Thread.CurrentPrincipal;
  p.IsInRole("rolesFromXml");
  </code></pre>
  
  <p>This works fine with one webrole instance since there is no big difference to normal IIS hosting. But will it still work with 2, 3 oder 5 instances? The Azure loadbalancer is not "sticky", users could be forwarded to another instance while using the application. Dunno if Thread.CurrentPrincipal is still the way to go. </p>
  
  <p>I use claims-based identity here. The first time an user enters the page, he gets forwarded to a security token service. Until now, this only happens once. It would be annoying if that happens several times when using multiple instances..</p>
  
  <p>Thanks!</p>