wkhtmltopdf.exe System.Security.SecurityException on cloud web server. How can i override server security policy

随声附和 提交于 2019-11-30 15:22:56

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..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!