views:

150

answers:

1

Is there a way to get the .ASPXAUTH value programatically.

Example I login to a website with my own credentials (POST) and then read the response...it does not return the .APSXAUTH in the CookieContainer that I use to track the session.

Anyone has a clue how can I get it and send it with the subsequent gets and posts?

[EDIT] here's what I do to be more specific:

  • send a HTTP GET to a page. read values like _VIEWSTATE etc.
  • send a HTTP POST to the Login page. It includes the login information.
  • The server sends a 302 response (redirect) to some Default page. The forms authentication cookie is supposed to be included but it's not.

So I was thinking that there might be a better way than this to track session:

CookieContainer _cookieJar = new CookieContainer();

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;

Thanks in advance for any answers.

+1  A: 

So the summarize the answer:

If you're trying to login programatically on a Forms based authentication website trough your own application make sure you follow the steps you take that track the cookies:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);
request.CookieContainer = _cookieJar;
HttpWebResponse httpsResponse = (HttpWebResponse)request.GetResponse();

The CookieContainer class handles the cookies as expected.

And if your response is encoded with Gzip just include the following line:

request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

before you call request.GetResponse()

Hope this helps someone out there.

bojanskr