title: Forms Authentication for a Silverlight application in Windows Azure
body: <p>I am migrating a n-tier Silverlight application to Windows Azure and I've hit a brick wall. Once I am logged in, the web service cannot know who is authenticated. My cloud project has two roles:</p>
  
  <ul>
  <li>Web UI: On Azure, its IP is 111.222.33.44:80</li>
  <li>Web Service: On Azure, its IP is 111.222.33.44:8080</li>
  </ul>
  
  <p><strong>Configuration for Web UI:</strong></p>
  
  <pre><code>&lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
      &lt;authentication mode="Forms"&gt;
          &lt;forms name="COOKIENAME" loginUrl="~/Login/login.aspx" timeout="2880" /&gt;
      &lt;/authentication&gt;
      &lt;authorization&gt;
          &lt;deny users="?" /&gt;
      &lt;/authorization&gt;
      &lt;machineKey validation="SHA1" decryption="AES" validationKey="VKEY" decryptionKey="DKEY"&gt;&lt;/machineKey&gt;
      &lt;pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" /&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p><strong>Configuration for Web Services</strong></p>
  
  <pre><code>&lt;system.web&gt;
      &lt;authentication mode="Forms"&gt;
          &lt;forms name="COOKIENAME" loginUrl="~/Login/login.aspx" timeout="2880" /&gt;
      &lt;/authentication&gt;
      &lt;authorization&gt;
      &lt;deny users="?" /&gt;
      &lt;/authorization&gt;
      &lt;machineKey validation="SHA1" decryption="AES" validationKey="VKEY" decryptionKey="DKEY"&gt;&lt;/machineKey&gt;
  &lt;/system.web&gt;
  </code></pre>
  
  <p>In the Web UI role, Login/login.aspx submits the username and password. A cookie is created with the method <code>FormsAuthentication.SetAuthCookie(username, myVar);</code>. Then, the user is redirected to <code>Default.aspx</code> which contains the Silverlight application. </p>
  
  <p>When it is starting, the Silverlight application gets the username from the Web Service role by returning <code>HttpContext.Current.User.Identity.Name</code>. </p>
  
  <p>All is fine in the local cloud emulator, but when I deploy my project in Windows Azure (staging), the web service doesn't know I am connected. I used Fiddler and I saw the page 111.222.33.44:8080/Login/login.aspx being queried (the page doesn't exist in the web service role, it is a way to know if a user is authenticated).</p>
  
  <p>I suspect the web service cannot retrieve the username because it cannot retrieve the cookie created by the Web UI role. Is it actually possible to make it work or do I have to merge the web service role with the Web UI role?</p>
  
  <p>The machine keys on both roles are identical.</p>