云网络服务器上的wkhtmltopdf.exe System.Security.SecurityException。 如何覆盖服务器安全策略

我希望我的网站有一个function,可以打印PDF格式的页面内容。 我尝试了一些选项,但最好的匹配是wkhtmltopdf,因为它也处理多语言字符。

我让它在我的本地服务器上工作,但当我将它上传到云服务器上进行托管时,它给了我以下错误

Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: System.Security.SecurityException: Request failed. 

我将安全策略更改为web.config

    

但它仍然无法正常工作

测试url为http://www.noor.com.asp1-20.dfw1-2.websitetestlink.com/ArticleDetails.aspx?Language=en-US&PageID=19&ArticleID=4

您可以单击背面的下载链接,此下载链接将网页的特定部分转换为PDF。 它在本地服务器上运行正常,但由于Web服务器上的安全原因而无法正常工作。 我已经找了几天让PDF工作,现在它不能在Web服务器上运行。 我尝试了其他选项,但他们iText由于某种原因它没有转换阿拉伯语它只是为阿拉伯语版本的页面打印垃圾字符。

请告知我应该改变什么以使其正确。

我使用c#开发了这个网站使用c#

我用来生成PDF的代码

 string url = "PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"]; // string args = string.Format("\"{0}\" - ", url); string args = string.Format("\"{0}\" - ", "http://www.domain.com.asp1-20.dfw1-2.websitetestlink.com/" + url); var startInfo = new ProcessStartInfo(Server.MapPath("bin\\wkhtmltopdf.exe"), args) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }; var proc = new Process { StartInfo = startInfo }; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output); proc.WaitForExit(); proc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf"); Response.BinaryWrite(buffer); Response.End(); 

工作代码:我通过调用MainPage.aspx中的PrintArticle.aspx解决了这个问题,当用户在lnkbtnDownload链接上发出粘连按钮时,它将调用页面PrinteArticle.aspx(打印文章页面是一个显示文章标题,日期和文章的简单页面说明)并将HTML传递给下面的代码,然后将其打印为PDF文件

  protected void lnkbtnDownload_Click(object sender, EventArgs e) { string url = "PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"]; string args = string.Format("\"{0}\" - ", "http://xyz.net/" + url); var startInfo = new ProcessStartInfo(Server.MapPath("bin\\wkhtmltopdf.exe"), args) { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true }; var proc = new Process { StartInfo = startInfo }; proc.Start(); string output = proc.StandardOutput.ReadToEnd(); byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output); proc.WaitForExit(); proc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf"); Response.BinaryWrite(buffer); Response.End(); } 

我传递其他参数作为查询字符串,如articleID,下载,语言等。