Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
142077 | Jan 17,2019 01:19 PM UTC | Jan 18,2021 04:40 PM UTC | ASP.NET MVC - EJ 2 | 11 |
![]() |
Tags: PDF Viewer |
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; }
………
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.