I am using Rotativa for convert the view to PDF. It works on my local but when published on IIS server it gives error as below:
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[Exception]
Rotativa.WkhtmltopdfDriver.Convert(String wkhtmltopdfPath, String switches, String html) +1364
Rotativa.WkhtmltopdfDriver.ConvertHtml(String wkhtmltopdfPath, String switches, String html) +70
Rotativa.ViewAsPdf.CallTheDriver(ControllerContext context) +1986
Rotativa.AsPdfResultBase.BuildPdf(ControllerContext context) +380
Rotativa.AsPdfResultBase.ExecuteResult(ControllerContext context) +69
projectName.Models.ViewAsPdf2.GetByte(ControllerContext context) in C:\Users\username\Documents\Visual Studio 2015\Projects\projectName\Models\ModelClass.cs:91
projectName.Controllers.<ModelClass>d__1.MoveNext() in C:\Users\username\Documents\Visual Studio 2015\Projects\projectName\Controllers\FormsController.cs:40
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +144
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +84
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +143
System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +23
System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +112
System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +452
System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15
System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +32
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +231
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
Not sure why the server is showing my local path for the controller context. I am using the default routing. Is there anything specifically that I need to modify?
Here is the code snippet that I use to pass the controller:
ControllerContext context = new ControllerContext(Request.RequestContext, this);
var pdf = new ViewAsPdf2("ModelClass", model);
byte[] pdfByteArray = pdf.GetByte(context);
Here is the code for GetByte
public class ViewAsPdf2: PartialViewAsPdf
{
public ViewAsPdf2(string viewName, object model) : base (viewName, model) {
}
public byte[] GetByte(ControllerContext context)
{
base.PrepareResponse(context.HttpContext.Response);
base.ExecuteResult(context);
return base.CallTheDriver(context);
}
}