Search code examples
c#asp.netrotativa

Rotativa not working when impersonate enabled on server


I am using Rotativa to generate a PDF from a view. It works on my localhost, but when I push to my server it does not work at all. The Server has Windows Authentication and Impersonate enabled which I need to have for this site.

This is the error I get when I try to run the code on the server

Qt: Could not initialize OLE (error 80070005) Error: Failed loading page https://api.mydomain.com/Reports/RedBluePDF?community=CommunityName&procedure=GetTasks (sometimes it will work just to ignore this error with --load-error-handling ignore) Exit with code 1 due to http error: 1003

Here is my code:

public byte[] getReportsPDF(string community, string procedure)
        {

            byte[] pdfBytes = new byte[] { };

            RouteData route = new RouteData();
            route.Values.Add("controller", "SiteSuperReports");
            route.Values.Add("action", "RedBluePDF");

            this.ControllerContext = new ControllerContext(new HttpContextWrapper(System.Web.HttpContext.Current), route, this);

            if (procedure == "GetProductionTasks")
            {

                var actionPDF = new Rotativa.ActionAsPdf("RedBluePDF", new { community = community, procedure = procedure })
                {
                    PageSize = Size.A4,
                    PageOrientation = Rotativa.Options.Orientation.Landscape,
                    PageMargins = { Left = 1, Right = 1 }
                };

                try
                {
                    pdfBytes = actionPDF.BuildFile(ControllerContext);
                }
                catch(Exception e)
                {
                    Console.Write(e.Message.ToString());
                }
            }

            return pdfBytes;
        }

And here is RedBluePDF Method, this just returns a View:

public ActionResult RedBluePDF(string community, string procedure) {
     return View();
}

What am I doing wrong and how come this is not working on my server, but is on my localhost? And How do I get it work on my server.


Solution

  • Try one of this solutions:

    1- Go to IIS > Site > Authentication, click on "ASP.NET Impersonation" and DISABLE it.

    2- If you're calling a script or a file or whatever, specify the used protocol:

    src="//api.mydomain.com/?????
    

    to:

    src="http://api.mydomain.com/?????
    

    3- In your Application Pool's configuration, under Process Model, there's an option "Load User Profile". It comes as False by default, set it as true.