Rotativa :: HTTP Error 401.2 – Unauthorized You are not authorized to view this page

Scenario

Using Rotativa as PDF convertor in ASP.NET MVC C# with Active directory login authentication

Problem

HTTP Error 401.2 – Unauthorized
You are not authorized to view this page due to invalid authentication headers

Cause :

If you use Rotativa.ActionAsPDF it will not pass the header values related to authentication to the new page. So option is to use Rotativa.PartialViewAsPdf

Sample Code:

 

public ActionResult ConvertToPDF(string stdId, string vid)
{
TestModel model = dbfunctions.GetTestValue(stdId, vid);
// send model as partial View Pdf not
return new Rotativa.PartialViewAsPdf(“TestPDF”, model);
}

public ActionResult TestPDF(TestModel model) // model with values
{
// PartialView(pdf) not View(pdf);
return PartialView(model);
}