如何解决System.Security.SecurityException:请求失败异常
我正在尝试使用 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's FAQ(“技术限制”)中提及。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。