I have a website that uses forms authentication and calls FormsAuthentication.SetAuthCookie
when the user has been validated, i.e FormsAuthentication.SetAuthCookie(userName, false)
.
I am currently creating HttpWebRequests and calling the website with the username and password and although the credentials pass validation - the response does not have any cokkies in its cookie collection.
The HTTP request/response code is below:
HttpWebRequest request = (HttpWebRequest) CreatePostRequest(baseAddress, postParameters);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
the code gets the response just fine and while debugging I can see the credentials being validated ok and the FormsAuthentication.SetAuthCookie(user, false) being called.
When I check the response cookie collection the count is 0. Can anyone help me understand why this is.
Thanks in advance.
You'll most probably find cookies in
response.Headers["Set-Cookie"]
. You can store these cookies in an instance ofCookieContainer
class simply byCookieContainer.SetCookies(baseAddress, response.Headers["Set-Cookie"]
and then using thisCookieContainer
instance in your subsequent requests. Hope this helps.