Problem with wkhtmltopdf. I use it to get pdf snapshots of pages on a website with username / password. When .exe starts, I get a snapshot of the login page (starting exe from my own ASP.NET application).
Does anyone know how I can get wkhtmltopdf to enter the site so that it can access the page on which it needs to take a picture?
wkhtmltopdf is installed in the program files directory on the server and is called through:
public void HtmlToPdf(string website, string destinationFile) { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "wkhtmltopdf.exe"; startInfo.Arguments = website + " " + destinationFile; Process.Start(startInfo); }
Thanks! --Dan
ANSWER
I couldn't get the -cookie-jar method to work (see comments), but I found another way to programmatically log in with the username / password in the query string.
I pass the username / pw as parameters in my query string and try to access the page I want with wkhtml. When the membership provider throws me to the login page, I access the parameters (which are stored in the URL as the returnUrl parameter) using the code and verify the authenticity. Simple response.redirect and bingo - I have my pdf snapshot.
// Check to see if an outside program is trying // to log in by passing creds in the querystring. if (Request.QueryString["username"] != null) && Request.QueryString["password"] != null)) { string user = Request.QueryString["username"]; string pw = Request.QueryString["password"]; if (System.Web.Security.Membership.ValidateUser(user, pw)) { // Create an authentication ticket for wkhtml session System.Web.Security.FormsAuthentication.SetAuthCookie(user, false); if (Request.QueryString["ReturnUrl"] != null) { Response.Redirect(Request.QueryString["ReturnUrl"]); } } else { throw new Exception("You failed to log in."); } }
Daniel Szabo
source share