0

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

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;
Cœur
  • 37,241
  • 25
  • 195
  • 267
TheBoyan
  • 6,802
  • 3
  • 45
  • 61
  • 1
    It should be there. Can you post your code so we can see? – David May 27 '10 at 13:20
  • You were right it was there, I just wasn't reading the response properly. I created another request whereas I should have just read the response with request.GetResponse(). I changed that and boom, there it was... But now everything is encoded...I cannot see anything in the text of the response. – TheBoyan May 28 '10 at 11:10
  • the answer to the second question (that everything is encoded) I found on the following thread: http://stackoverflow.com/questions/678547/does-nets-httpwebresponse-uncompress-automatically-gziped-and-deflated-response – TheBoyan May 28 '10 at 12:20

1 Answers1

1

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.

First create a initial GET request, and then do the subsequential POST requests that will do the postback.The request and the responses should be formulated in this way:

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.

TheBoyan
  • 6,802
  • 3
  • 45
  • 61