Get ASP.NET authentication cookies with Mechanize

270 Views Asked by At

I'm trying to sign into and establish a session on an ASP.NET site programmatically using Ruby Mechanize. The problem is that I cannot seem to be able to grab the three cookies required for login/authentication.

For example, when using a normal browser, such as Chrome, after the browser makes a POST request to the login form with the username and password, three cookies are set:

  • ASPXAUTH
  • ASP.NET_SessionId
  • UserName

When using Mechanize to try and log in, after the login form is submitted, the Mechanize agent's Mechanize::CookieJar only contains one cookie: ASP.NET_SessionID.

This obviously causes any subsequent requests for pages behind login to fail and complain that "The session is expired" and to "please sign in again."

Is there anyway I can grab the other two cookie programmatically? It doesn't have to necessarily be through Mechanize, but there has to be some way to pass this cookie to it.

1

There are 1 best solutions below

0
On BEST ANSWER

It turns out that some (most) ASP.NET button clicks are handled via Javascript. The current version of Mechanize (2.7) does not support Javascript interaction. I switched to Capybara WebKit as the headless driver. I was able then able to interact with the buttons I needed.