0

I'd like to make several pdfs from pages that are sitting behind a login page. When I try doing the basic info from their page:

        var htmlToPdf = new HtmlToPdfConverter();

        htmlToPdf.GeneratePdfFromFile("url-of-page", null, "export.pdf");

I get the page the site offers when you're not logged in.

And when I try giving it cookies (the site has 2):

        var htmlToPdf = new HtmlToPdfConverter();

        htmlToPdf.CustomWkHtmlArgs = " --cookie name1 value1";
        htmlToPdf.CustomWkHtmlArgs = " --cookie name2 value2";

        htmlToPdf.GeneratePdfFromFile("url-of-page", null, "export.pdf");

I get the log in page. As if I've entered something wrong, but I get the cookies 1 to 1 from Postman.

Am I using a wrong format for the name and value?

I tried going through an httpClient, and the cookies work there and I get to the page, but I cant get the pictures and css when I do it like that.

cybera
  • 351
  • 2
  • 17
  • I think It adds 2 different cookies. I'm not sure how to add them both on 1 line. Do you have an idea? – cybera Oct 30 '17 at 10:10
  • When you do `var s = ""; s = "bob"; s = "cathy";` What is the value of `s` after that? Similarly, what is the value of `htmlToPdf.CustomWkHtmlArgs` after assigning it twice? – mjwills Oct 30 '17 at 10:11
  • That makes sense, I'm left with the problem of how to add 2 cookies on 1 line, do you have an idea what the syntax should look like? – cybera Oct 30 '17 at 10:14
  • hmm, for some unknown reason it works when I add just one of the 2 cookies, how does it work with just one of them however I don't know. – cybera Oct 30 '17 at 10:19
  • It was the sessionid, the other one was the username. – cybera Oct 30 '17 at 10:47

1 Answers1

0

I had same problem and "NReco" just had access to my login page . In the web config file of my project , my authentication setting was as below :

  <system.web>
    <authentication mode="Forms">
      <forms loginUrl="~/login.aspx"/>
    </authentication>
  </system.web>

Then I add the name attribute to forms as it makes a session with the same name like this :

  <system.web>
    <authentication mode="Forms">
      <forms name="ACUID" loginUrl="/Login" protection="All" path="/" timeout="60" />
    </authentication>
  </system.web>

and finally again in my web config files in authorization setting I change it from :

  <authorization>
    <deny users="?" />
  </authorization>

TO :

  <authorization>
    <allow users="*" />
    <deny users="?" />
  </authorization>
Reza Rahgozar
  • 99
  • 1
  • 7