I have a .NET MVC3 application and a WCF service. The app requires all users to be authenticated.
Now, I want to get the content of one secured page with WebClient from my WCF service.
Both, service and the web application run on the same server, under the same CNAME (different ports).
I thought that I could create a cookie like this:
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)
I add the cookie to the request, but I still do not get the content as I am unauthorized.
I thought that maybe FormsAuthentication class properties are not set correctly, so I tried "/"
instead of FormsAuthentication.FormsCookiePath
and "".ASPXAUTH""
instead of FormsAuthentication.FormsCookieName
. It still does not work.
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?