Using wkhtmltopdf inside asp.net mvc takes a long time to get started

I use wkhtmltopdf to load a page and create a pdf, as described in here . Everything works as expected, but when it reaches the next line:

int read = proc.StandardOutput.BaseStream.Read(buffer, 0, buffer.Length); 

It takes a lot of time to continue. I also tried the following:

 proc.Start(); string output = proc.StandardOutput.ReadToEnd(); string error = proc.StandardError.ReadToEnd(); proc.WaitForExit(); 

But the same thing happens on line 2 ( proc.StandardOutput.ReadToEnd() ).

How can I debug this?

Note. Since I am debugging the entire project, I see that the page called by the wkhtmltopdf process is only called after a delay. Thus, a delay occurs between the OS call and the page load itself.


Edit

So, I changed some of the arguments to just http://google.com - and executed pretty quickly.

So, the problem is somewhere in my full argument: --stop-slow-scripts --redirect-delay 1500 --cookie MOODLEID_ %25E2%25C8%2513E%25BD --cookie ASP.NET_SessionId mg3mfaisk45zn5y1aql0glbb --cookie .ASPXAUTH FEA3D10032E211EDB330E967D8F19A324A912AD792219CA281451AA809F1B580B25466DAF81DE30DF07252FF13F0888C88ED4DB5871579F1DA3EBAA447CBF860131F6FF00A763C9207CE13BCB143301E49A2B00EEBBF1F4AE14F109DF1BE8D3B39C43478B99E4C686C3849D1D51DDBFA3D2E871691BAB8346FE5195D867F88F662F72E40 http://localhost:8404/Relatorio/GeralEstaticoPDF?id=15&pesq_cod=0&IncluirParciais=True&NomesImagens[0]=3fd5b6a2-76a4-470b-af99-93500cc90431.png&NomesImagens[1]=c1c86234-c338-4285-9d25-5069be36a213.png&NomesImagens[2]=4562f9a3-72aa-452c-9736-6d0ba65f59ce.png&NomesImagens[3]=dbc54344-6248-4ee3-9e43-9cb3ef89cc67.png&NomesImagens[4]=8c954917-d572-4d4a-b6fd-2b9cd09e8f8e.png - % 25BD --cookie ASP.NET_SessionId mg3mfaisk45zn5y1aql0glbb --cookie .ASPXAUTH FEA3D10032E211EDB330E967D8F19A324A912AD792219CA281451AA809F1B580B25466DAF81DE30DF07252FF13F0888C88ED4DB5871579F1DA3EBAA447CBF860131F6FF00A763C9207CE13BCB143301E49A2B00EEBBF1F4AE14F109DF1BE8D3B39C43478B99E4C686C3849D1D51DDBFA3D2E871691BAB8346FE5195D867F88F662F72E40 http --stop-slow-scripts --redirect-delay 1500 --cookie MOODLEID_ %25E2%25C8%2513E%25BD --cookie ASP.NET_SessionId mg3mfaisk45zn5y1aql0glbb --cookie .ASPXAUTH FEA3D10032E211EDB330E967D8F19A324A912AD792219CA281451AA809F1B580B25466DAF81DE30DF07252FF13F0888C88ED4DB5871579F1DA3EBAA447CBF860131F6FF00A763C9207CE13BCB143301E49A2B00EEBBF1F4AE14F109DF1BE8D3B39C43478B99E4C686C3849D1D51DDBFA3D2E871691BAB8346FE5195D867F88F662F72E40 http://localhost:8404/Relatorio/GeralEstaticoPDF?id=15&pesq_cod=0&IncluirParciais=True&NomesImagens[0]=3fd5b6a2-76a4-470b-af99-93500cc90431.png&NomesImagens[1]=c1c86234-c338-4285-9d25-5069be36a213.png&NomesImagens[2]=4562f9a3-72aa-452c-9736-6d0ba65f59ce.png&NomesImagens[3]=dbc54344-6248-4ee3-9e43-9cb3ef89cc67.png&NomesImagens[4]=8c954917-d572-4d4a-b6fd-2b9cd09e8f8e.png -

I need cookies to save the session.

If I ran this directly on the command line (but instead of a name - instead of a name - ), it will work quickly.


Edit 2

So the problem is, of course, cookies, if I delete them, they execute quickly, but that only gives me a PDF login screen, since it does not save the session.

+4
source share
3 answers

The answer is correct, but I wanted to add a possible solution for any future visitors.

In short:

Adding the [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] attribute to the controller (printing) resolved the problem for me.

I actually use the Rotativa library, which in turn uses wkhtmltopdf.

(Perhaps it would be useful to add the Rotativa tag to the question?)

+2
source

It seems that the session cookie is causing the problem, auth forms are okay or any other cookies, for that matter. The reason is this:

"To avoid data conflicts in the session store and unanticipated behavior of the session state, the SessionStateModule and SessionStateStoreProviderBase classes include lock functions that only block the session storage element for a particular session for the entire duration of the ASP.NET page."

http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstatestoreproviderbase%28VS.80%29.aspx

+1
source

I will add my experience, as I came across it in two different projects.

My options for creating pdf:

 string[] options = new string[] { "--cookie", "ASP.NET_SessionId", System.Web.HttpContext.Current.Session.SessionID, "--cookie", ".ASPNETAUTH", HttpContext.Current.Request.Cookies[".ASPNETAUTH"].Value}; 

Then I add: EnableSessionState="ReadOnly" to the caller page header, and it works.

0
source

Source: https://habr.com/ru/post/1401512/


All Articles