云计算的Web服务器上wkhtmltopdf.exe System.Security.SecurityException。我如何可以覆盖服务器的安全策略 [英] wkhtmltopdf.exe System.Security.SecurityException on cloud web server. How can i override server security policy

查看:118
本文介绍了云计算的Web服务器上wkhtmltopdf.exe System.Security.SecurityException。我如何可以覆盖服务器的安全策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的网站功能,可以打印网页内容为PDF。我想这几个选项,但最匹配的wkhtmltopdf,因为它也处理多语言字符。

我知道了我的本地服务器上的工作,但是当我上传云端的Web服务器上托管现在是给我下面的错误

 安全例外
说明:应用程序试图执行不是由安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系或更改配置文件中的应用程序的信任级别。异常详细信息:System.Security.SecurityException:请求失败。

我在web.config中改变了安全策略

 <&SECURITYPOLICY GT;
  < trustLevel NAME =全policyFile =内部/>
< / SECURITYPOLICY>

但它仍然没有工作。

测试网址是
<一href=\"http://www.noor.com.asp1-20.dfw1-2.websitetestlink.com/ArticleDetails.aspx?Language=en-US&PageID=19&ArticleID=4\" rel=\"nofollow\">http://www.noor.com.asp1-20.dfw1-2.websitetestlink.com/ArticleDetails.aspx?Language=en-US&PageID=19&ArticleID=4

您可以点击这个下载链接网页的特定部分转换为PDF后面的下载链接。它的工作原理本地服务器上的罚款,但它不工作在Web服务器上的安全性原因。我已经看了好几天拿到PDF的工作,现在它不工作在Web服务器上。我尝试过其他的选择,但他们的iText由于某种原因,它不仅对网页的阿拉伯文版转换阿拉伯语它打印垃圾字符。

请指教一下我应该改变,以得到它的权利。

我已经开发使用asp.net 4.0使用本网站的C#

code我用它来生成PDF

 字符串的URL =?PrintArticle.aspx条款ArticleID =+请求[条款ArticleID] +&放大器;下载= YES&安培; LANGUAGE =+请求[语言];//字符串ARGS =的String.Format(\\{0} \\ - ,URL);
字符串ARGS =的String.Format(\\{0} \\ - ,http://www.habtoor.com.asp1-20.dfw1-2.websitetestlink.com/+网址);
VAR的StartInfo =新的ProcessStartInfo(使用Server.Mappath(本\\\\ wkhtmltopdf.exe),参数)
{
        UseShellExecute =假,
        CreateNoWindow = TRUE,
        RedirectStandardOutput =真};
VAR PROC =新的Process {StartInfo的=的StartInfo};
proc.Start();字符串输出= proc.StandardOutput.ReadToEnd();
字节[]缓冲= proc.StandardOutput.CurrentEncoding.GetBytes(输出);
proc.WaitForExit();
proc.Close();
Response.ContentType =应用程序/ PDF
Response.AddHeader(内容处置,附件;文件名= download.pdf);
Response.BinaryWrite(缓冲液);
到Response.End();


解决方案

工作code:
我从MainPage.aspx调用PrintArticle.aspx,当用户clinks在 lnkbtnDownload 链接按钮,它会调用页面PrinteArticle.aspx(打印文章页是解决该问题一个简单的网页,其中显示文章标题,日期和文章说明),并通过HTML到code以下,然后将打印为PDF文件

 保护无效lnkbtnDownload_Click(对象发件人,EventArgs的发送)
    {
        字符串的URL =?PrintArticle.aspx条款ArticleID =+请求[条款ArticleID] +&放大器;下载= YES&安培; LANGUAGE =+请求[语言];        字符串ARGS =的String.Format(\\{0} \\ - ,http://xyz.net/+网址);
        VAR的StartInfo =新的ProcessStartInfo(使用Server.Mappath(本\\\\ wkhtmltopdf.exe),参数)
        {
            UseShellExecute =假,
            CreateNoWindow = TRUE,
            RedirectStandardOutput =真        };
        VAR PROC =新的Process {StartInfo的=的StartInfo};
        proc.Start();        字符串输出= proc.StandardOutput.ReadToEnd();
        字节[]缓冲= proc.StandardOutput.CurrentEncoding.GetBytes(输出);
        proc.WaitForExit();
        proc.Close();
        Response.ContentType =应用程序/ PDF
        Response.AddHeader(内容处置,附件;文件名= download.pdf);
        Response.BinaryWrite(缓冲液);
        到Response.End();
    }

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

I want to have a feature for my website which can print the page contents as PDF. I tried a few option for this but the best match was wkhtmltopdf as it also handle multilingual characters.

I got it working on my local server but when I uploaded it on a cloud web server for hosting now it is giving me the following error

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.

I changed the security policy to in web.config

<securityPolicy>
  <trustLevel name="Full" policyFile="internal"/>
</securityPolicy>

But it is still not working

Test URL is http://www.noor.com.asp1-20.dfw1-2.websitetestlink.com/ArticleDetails.aspx?Language=en-US&PageID=19&ArticleID=4

You can click the Download link on the back this download link convert the particular section of web page to PDF. It works fine on local server but it is not working for security reason on the web server. I had looked for days to get the PDF working and now it is not working on the web server. I tried other option but they iText for some reason it was not converting arabic it was printing junk characters only for arabic version of page.

Please advise what I should change to get it right.

I have developed this website using asp.net 4.0 using c#

Code I use to generate 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.habtoor.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();

解决方案

WORKING CODE: I resolved the issue by calling the PrintArticle.aspx from MainPage.aspx, When user clinks on the lnkbtnDownload link Button it will call the page PrinteArticle.aspx (Print Article Page is a simple page which show article title, date and Article Description) and pass the HTML to the code below which will then print it as a PDF file

   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();
    }

I am passing other parameters as query string like articleID, Download, Language etc..

这篇关于云计算的Web服务器上wkhtmltopdf.exe System.Security.SecurityException。我如何可以覆盖服务器的安全策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆