codaxy / wkhtmltopdf

C# wrapper around excellent wkhtmltopdf console utility.
265 stars 92 forks source link

Support for url behind Identity Authentication (.NET MVC 5) #17

Closed HugCoder closed 7 years ago

HugCoder commented 8 years ago

I'm trying to use your wrapper in order to generate a PDF file of a html page containing an invoice in ASP.net MVC 5. This is a order system where it's, of course, protected from the public by log in and cookie authentication using Identity. I tried adding Cookies by doing:

 var cookies = Request.Cookies.AllKeys.ToDictionary(k => k, k => Request.Cookies[k].Value);

 Codaxy.WkHtmlToPdf.PdfConvert.ConvertHtmlToPdf(new Codaxy.WkHtmlToPdf.PdfDocument
        {
            Url = Request.Url.AbsoluteUri.Replace("pdf", "print"),
            HeaderLeft = "[title]",
            HeaderRight = "[date] [time]",
            FooterCenter = "Page [page] of [topage]",
            Cookies = cookies

        }, new Codaxy.WkHtmlToPdf.PdfOutput
        {
            OutputFilePath = Server.MapPath("~/Content/InvoicePDFs/"+ id.ToString() + ".pdf")
        }
return File("~/Content/InvoicePDFs/" + id.ToString() + ".pdf", "application/pdf", id.ToString() + ".pdf");
        );

But I just end up rendering the login page, and barely that, it's not even completely loaded. It just renders the elements, no text whatsoever.

mstijak commented 7 years ago

This is outside the scope of this project.

I solved a similar issue once by writing my own auth logic (attribute) which enables time limited token based access.