簡體   English   中英

System.Security.SecurityException:請求失敗異常

[英]System.Security.SecurityException: Request failed exeception

我正在嘗試使用NReco.PdfGenerator從 HTML 數據生成 PDF。

public static MemoryStream HtmlToPDFConvert(string html)
{
    HtmlToPdfConverter pdfConverter = new HtmlToPdfConverter();
    pdfConverter.Size = NReco.PdfGenerator.PageSize.A4;
    var pdfBytes = pdfConverter.GeneratePdf(html);
    var ms = new MemoryStream(pdfBytes);
    return ms;
}

代碼在我的本地機器上運行良好,但在服務器(plesk 共享主機)上運行代碼時出現以下錯誤。

System.Security.SecurityException: Request failed.     at MyClass.MyMethod(string arguments)     at b_Submit_Click(Object sender, EventArgs e)  The action that failed was:  LinkDemand  The type of the first permission that failed was:  System.Security.PermissionSet  The Zone of the assembly that failed was:  MyComputer

看起來錯誤是因為,NReco 正在嘗試為 wkhtmltopdf 生成 exe 文件,但服務器不允許生成該 exe 文件。

有沒有辦法解決這個問題? 提前致謝。

您不能在共享主機上使用 NReco.PdfGenerator,因為當您調用GeneratePdf方法包裝器時,會使用 System.Diagnostics.Process API 執行 wkhtmltopdf.exe。 在大多數共享主機上,禁止使用此 API,並且不可能從 ASP.NET 應用程序啟動另一個進程。

NReco.PdfGenerator 的常見問題解答(“技術限制”)中提到了此限制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM