Welcome Guest Search | Active Topics | Sign In | Register

New Session ID when calling RenderAsPDF Options
Cu4IT
Posted: Friday, June 17, 2016 12:44:13 PM
Rank: Newbie
Groups: Member

Joined: 8/26/2013
Posts: 6
Hi everyone,

I'm having some issues with the following project:
- EO.PDF .NET 15.2.53.0
- ASP.NET 4.5.2 with hybrid Webforms + MVC 4

Below is my controller method.

Code: C#
using EO.Pdf;
using EO.Pdf.Mvc;
        [RenderAsPDF]
        public ActionResult PrintCalendar(string yearString, string monthString)
        {
            string fileName = string.Format("calendar");
            MVCToPDF.ResultFileName = fileName;

            HtmlToPdf.Options.PageSize = new SizeF(PdfPageSizes.A4.Height, PdfPageSizes.A4.Width);

            const float marginLeft = 0.2f;
            const float marginTop = 0.2f;
            float pageHeight = PdfPageSizes.A4.Height - (marginTop * 2);
            float pageWidth = PdfPageSizes.A4.Width - (marginLeft * 2);

            HtmlToPdf.Options.OutputArea = new RectangleF(marginLeft, marginTop, pageHeight, pageWidth);
            HtmlToPdf.Options.ZoomLevel = 0.8f;

            HtmlToPdf.DebugConsole = Console.Out;
            HtmlToPdf.Options.MinLoadWaitTime = 5000;

            MVCToPDF.ResultAsDownload = true;
            MVCToPDF.RenderAsPDF();

            return View();
        }


Within this View, I put some Javascript that calls another Controller Method to get some data. That's why I set at least 5 seconds load time. Calling this View without the RenderAsHtml command, works perfect.

When I call this (httpget) method, a download/save file as... dialog appears, but then nothing happens. I've waited for about 10 minutes. Also nothing is visible in the Debug-output console. The breakpoint on the controller method returning the data isn't hit.

Because I've registered the AuthorizeAttribute filter, I think the request might be unauthenticated?
Code: C#
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new AuthorizeAttribute());
        }


To solve this, I thought it might be good to add the Authentication cookie to the HtmlToPdf.Options. When I just add all the cookies, it still doesn't respond. So I just add the FormsAuthentication cookie:

Code: C#
for (int i = 0; i < Request.Cookies.Count; i++)
            {
                HttpCookie httpCookie = Request.Cookies[i];
                if (string.Equals(httpCookie.Name, "User", StringComparison.OrdinalIgnoreCase))
                {
                    HtmlToPdf.Options.Cookies.Add(new Cookie() { Name = httpCookie.Name, Domain = httpCookie.Domain, Path = httpCookie.Path, Secure = httpCookie.Secure, Value = httpCookie.Value, Expires = httpCookie.Expires });
                }
            }


Then it works! My controller method, called by javascript, hits the breakpoint. But the Session ID is different. So it looks like it's run on a different thread or something creating a new Session ID. That's a problem, I'm missing some required data.

When I add the Session-cookie, the same way as I do with the authentication cookie, it hangs again. No breakpoint is hit.

So my first question is, am I using EO.PDF correct? Given the Hybrid webforms/MVC and EO version. Offcourse I've setup licence key and:
Code: C#
EO.Pdf.Mvc.MVCToPDF.RegisterFilter(typeof(GlobalFilters));


Am I doing the authentication-trick correct? I've seen a property MVCToPDF.AutoFormsAuthentication = true|false; but that doesn't seem to make any difference. Also I can't find the MVC4 namespace for using the RenderAsPDF-attribute?

Many thanks in advance.
eo_support
Posted: Sunday, June 19, 2016 11:48:25 PM
Rank: Administration
Groups: Administration

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

This might be a session lock issue. If you remove your cookie code and run it in debugger, then during the long wait when nothing happens you break your application, can you see the stack trace for the other request that comes from your JavaScript? My guess is that request is blocking on trying to acquire session state data.

In any case, if you can isolate the problem into a test project and send the test project to us, we will be happy to look further and see what we can find.

Thanks!
Cu4IT
Posted: Friday, July 1, 2016 4:53:40 AM
Rank: Newbie
Groups: Member

Joined: 8/26/2013
Posts: 6
Thank you for your feedback.

I think it's related to a Session Lock indeed. But now I'm trying to figure out how to solve this. I created blank new Views without any dependancies to JS, CSS or Html-helpers. Just as long as I don't add something into the Session State - it responds quickly. But when I add something like Session["test"] = "random text" - EO.PDF takes about 140 seconds to respond. Also, setting the property "MVCToPDF.AutoFormsAuthentication = true;" affects this result. When I set this to false, it generates the PDF within 10 seconds. That's great. But then it cannot access the authenticated ActionMethod that javascript uses to retrieve the data.

I isolated into a new (clean) MVC application. I will send it to you with instructions. Many thanks in advance if you can take a look.

EDIT: The project runs on local IIS. This way I hope to eliminate any DNS issues.
eo_support
Posted: Monday, July 4, 2016 9:08:57 PM
Rank: Administration
Groups: Administration

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

Can you try the latest version from our download page and see if it works for you? We tested your test project with the latest version and it seems to work fine. It does demonstrate the problem with the old version your sample project uses. It seems that the problem is caused by the much older browser engine your version uses, even though we are still trying to pin point the exact cause. The current version uses a much newer browser engine and it does not have this issue.

Thanks!
Cu4IT
Posted: Wednesday, July 6, 2016 4:23:43 AM
Rank: Newbie
Groups: Member

Joined: 8/26/2013
Posts: 6
Thank you for your response. We've downloaded the latest EO.PDF version and this Session-lock'ish issue is fixed. Now this works, another problem surfaced which we cannot seem to resolve.

I've set the MinLoadWaitTime to various values. 1000ms, 5000ms and 10000ms. No matter what the WaitTime is, the jquery $.Ajax call is only called after the PDF is rendered. I've tested this with the use of breakpoints and Debug.WriteLine();.

I've send you an support e-mail with a isolated solution.

I hope you can take a look at this.
Cu4IT
Posted: Wednesday, July 6, 2016 4:30:26 AM
Rank: Newbie
Groups: Member

Joined: 8/26/2013
Posts: 6
Two more items that might help:

1) If you start the webapplication directly to /Home/About, and assuming you've logged in previous, it's works. The Ajax data is immediately received.
2) I've set HtmlToPdf.DebugConsole = Console.Out; But console.log('test') does not write anything to my Debug-output window in VS2015.
eo_support
Posted: Wednesday, July 6, 2016 9:57:02 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,275
Thanks for the additional information. We will look into this and get back to you as soon as possible.
eo_support
Posted: Thursday, July 7, 2016 5:04:15 PM
Rank: Administration
Groups: Administration

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

We have posted a new build that should fix this problem. Please download the new build from our download page and let us know how it goes.

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.