Search code examples
asp.net-mvcpdfwkhtmltopdfrotativaadfs3.0

Rotativa + WkhtmltoPDF + ADFS not rendering PDF


I have an ASP.net MVC application where I can't get the MVC Views to render as a PDF after the introduction of the ADFS authentication.

Earlier, the application had Forms authentication and PDF rendering using Rotativa (which uses WkhtmltoPDF library) worked like a charm. After the introduction of the ADFS it just won't work.

What I get is a blank PDF with the title: "Sign In" without any elements on the page/PDF itself.

enter image description here

As it's pretty indicative that it tries to connect somewhere I believe the problem lies somewhere in the authentication parameters of the WkhtmltoPDF i.e. I probably have to add some additional parameters in order to support ADFS, but I'm not sure which ones. I've already tried using --username and --password parameters but they didn't help.

The question is: What to do to make it work (again)?


Solution

  • I wasn't able to fix the problem the way I wanted it to, but for those interested in the solution the next steps describe what I did.

    As the page I was trying to render with Rotativa required authentication I added the logic to create an "one-time access token" which redirects the user to the another application that renders the same page but without any ADFS authentication check. In this case you have to modify Rotativa's logic to return UrlAsPdf instead of ActionAsPdf.

    The only authorization thing I did was checking the validity of the token. Since the token has a fast expiration time (it is valid only for the next couple of minutes) I don't think the security of the web app was negatively affected since no one can access the version without authentication without the access token.