title: How to create an authentication cookie in the WCF Service that makes a request to a secured site?
body: <p>I have a .NET MVC3 application and a WCF service. The app requires all users to be authenticated.</p>
  
  <p>Now, I want to get the content of one secured page with WebClient from my WCF service.</p>
  
  <p>Both, service and the web application run on the same server, under the same CNAME (different ports).</p>
  
  <p>I thought that I could create a cookie like this:</p>
  
  <pre><code>Dim ticket = New FormsAuthenticationTicket(1, adAccount, DateTime.Now, DateTime.Now.AddMinutes(30), False, Nothing, FormsAuthentication.FormsCookiePath)
  
  ' Encrypt the ticket using the machine key
  Dim encryptedTicket = FormsAuthentication.Encrypt(ticket)
  
  ' Add the cookie to the request to save it
  Dim cookie = New HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
  </code></pre>
  
  <p>I add the cookie to the request, but I still do not get the content as I am unauthorized.</p>
  
  <p>I thought that maybe FormsAuthentication class properties are not set correctly, so I tried <code>"/"</code> instead of <code>FormsAuthentication.FormsCookiePath</code> and <code>"".ASPXAUTH""</code> instead of <code>FormsAuthentication.FormsCookieName</code>. It still does not work.</p>
  
  <p>Does anyone have an idea how I can create a valid cookie in my WCF service, so I can request the secured pages of my web application that requires authorization?</p>