Welcome Guest Search | Active Topics | Sign In | Register

Unauthorized Access 401 Error Options
Kataria Deepak
Posted: Wednesday, October 16, 2019 4:42:01 AM
Rank: Newbie
Groups: Member

Joined: 10/15/2019
Posts: 8
Hi Team,

I am trying to convert Share Point Online Form to PDF using EO.PDF (4.0).

Following is the code snippets

PdfDocument doc = new PdfDocument();
HtmlToPdf.Options.MinLoadWaitTime = 40000;
HtmlToPdf.Options.Cookies = response.Cookies;
HtmlToPdf.ConvertUrl(uri, doc);
doc.Save(Server.MapPath(Path.Combine("~/PDF/", randomNumber + ".pdf")));

I am getting an error in the generated PDF "401 Unauthorized" even passing the cookies (authentication).

Thanks in Advance
eo_support
Posted: Wednesday, October 16, 2019 10:54:35 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

Please update to the latest version and then use the built-in debugger feature to check the cookies that were sent. See here for how to use the built-in debugger feature:

https://www.essentialobjects.com/doc/webbrowser/advanced/debug.aspx#debug_ui

The documentation is for EO.WebBrowser, however it applies to EO.Pdf as well since internally EO.PDf uses EO.WebBrowser to render the page.

Once you open the debug interface, you can then go to the Network tab to check the cookies and response. You can then compare this traffic with the traffic you see in Google Chrome browser to find out what's wrong.

Thanks!
Kataria Deepak
Posted: Friday, October 18, 2019 1:32:54 AM
Rank: Newbie
Groups: Member

Joined: 10/15/2019
Posts: 8
Thanks for your kind reply.

I have applied the code as per below

Code: C#
HtmlToPdfOptions op = new HtmlToPdfOptions();
            op.MinLoadWaitTime = 20000;
            op.Cookies.Add(new Cookie("_InfoPath_CanaryValueAEIOV3VMYXDMGTNTHUD4DMLK2KFBSL2IJBJEKQZPIZXXE3LTF52GK3LQNRQXIZJOPBZW4KSOOJYUKSCVHE3FIV3RIVGHCM3PJEYWO6KJMVAXUSDWI5BEQ3BRIFWWSZ3KI5HDK4ZYLE", "5mO93KiJg9nkCoc5PGKpzWpQV7J46x3Jwp2W5hTYqtKiYCwoCwiKQhcVf1TBV91Q+MPz43lG5tXURZqlVDXj2A==|637068981942426752"));
            //  HtmlToPdf.Options.Cookies = response.Cookies;
            op.Cookies.Add(new Cookie("WSS_KeepSessionAuthenticated", "{255efb5e-8eda-47c5-9fcf-4b4833cff4d5}"));

            HtmlToPdf.ConvertUrl(uri, doc,op);
            EO.WebBrowser.WebView.ShowDebugUI();


EO.WebBrowser Debug UI control shows me, there is no cookies containing in application tab of console. but I am sending cookies in the HtmlToPdfOptions. Please help me what missing in the code.

Thanks in Advance
eo_support
Posted: Friday, October 18, 2019 11:58:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,080
Hi,

We apologize. Please try to use a third party traffic monitor such as Fiddler to check and debug the traffic.

There are two types of cookies: those that you sent to the Web server and those that the web server sent to you. In a normal environment, they are usually the same: because the primary reason for the web server sends a cookie for you to send it back to the server at a later time.

In your case they are not the same because you are trying to attach cookies manually through code. The "Application" tab shows you the cookies the web server send to you. Your cookies will not appear here because yours is of the opposite direction.

In order to see cookies you send to the web server, you must go to the "Network" tab and then click "Record" before sending the request. This would be difficult for the HTML to PDF converter because by the time you get to the "Network" tab, the request has already been sent. As such it should try to use another traffic monitor to troubleshoot such issues. We tried using Fiddler and we did see the cookies are correctly sent to the server. So the issue is somewhere else.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.