WebAPI Controller:
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(“http://localhost /api/PdfViewer/”)
In “api/pdfViewer” where pdfviewer refers to the name of the webAPIController (api/webAPIControllername)
(or)
MVC Controller:
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(“http://localhost /PdfViewer/”)
In “/pdfViewer” where pdfviewer refers to the name of the MVCController (MVCcontrollername)
//where localhost=http://192.168.0162:81 according to the provided snippet
Note: Please use the webAPIControllername/ MVCcontrollername name as per you have provided in your hosted webservice.
|
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/api/PdfViewer/")).DocumentPath("PDF_Succinctly.pdf").Render()
|
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentPath("PDF_Succinctly.pdf").Render()
|
Query |
Details | |
On investigating further, I found that, one of my middleware has
await _antiforgery.ValidateRequestAsync(context);
The call to PdfViewer action 'Load' causes exception at the above line. Thus, I want to know how to pass antiforgery token along with PefViewer actions.
|
We can include the Authorization token in the PDF Viewer AJAX request using the ajaxRequest headers properties available in AjaxRequestSettings and it will be included in every AJAX request send from PDF Viewer. | |
Also, I have downloaded .NET 4.6.1 sample and it's posting proper object in jsonObject
public ActionResult Load(jsonObjects jsonObject)
but in ASP.NET Core 3.1, its able to reach controller after commenting antiforgery token check, but jsonObject is null
public IActionResult Load([FromBody] Dictionary<string, string> jsonObject) <== jsonObject is null.
|
Based on the provided details we suspect that NewtsonSoft.Json is not configured properly so the errors occurs.So kindly configure it in your .core 3.1 project as below.
Prior to ASP.NET Core 3.0, the default JSON formatters implemented using the Newtonsoft.Json package. In ASP.NET Core 3.0 or later, the default JSON formatters are based on System.Text.Json. Support for Newtonsoft.Json based formatters and features is available by installing the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package and configuring it in Startup.ConfigureServices.
Please try it and if you are still facing the issue , revert us with the modified sample in which the issue could be reproduced. Also confirm us whether you are using the PDF Viewer in ASP.Net Core MVC or Razor pages.
|
public IActionResult OnPostLoad([FromBody] jsonObjects responseData)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
MemoryStream stream = new MemoryStream();
var jsonObject = JsonConverterstring(responseData); // converted the class to type to Dictionary<string,string> type
……………
}
public class jsonObjects
{
public string document { get; set; }
public string password { get; set; }
public int zoomFactor { get; set; }
public bool isFileName { get; set; }
………
} |
Hi there,
I'm having the same issue. Problem with loading pdf, also showing Web-service is not listening.
Please see attached pdf files. These pdfs do not show also on your demo.
Here in google drive: https://drive.google.com/drive/folders/1PYjTe6QfvhJStdBemrkuySMlghhf7V5F?usp=sharing
Regards,
Marvin
Attachment: PDFs_7f5d6c2c.zip
Hi Marvin,
We were able to reproduce the reported issue with the provided document. We will analyze further on this and update you with more details on April 19, 2022.
Regards,
Vasugi.
Hi Marvin,
We can resolve
the reported issue by providing the maxAllowedContentLength and request length
on the web. config file. And need
to increase the maximum length for serializing the large-sized JSON object. So, we have created a class LargeJsonValueProviderFactory and modified the code to increase the length for serialization
in the file Global.asax.cs. Kindly refer to
the below code snippet and sample.
Code Snippet:
<httpRuntime targetFramework="4.7.2" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />
<requestLimits maxAllowedContentLength="2147483647" />
|
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/GettingStarted_MVC2051814703
Kindly try this and let us know if this helps you.
Regards,
Vasugi