wkhtmltopdf.exe system.security.securityException su Cloud Web Server. Come posso sovrascrivere la politica di sicurezza del server

StackOverflow https://stackoverflow.com/questions/9478141

  •  13-11-2019
  •  | 
  •  

Domanda

Voglio avere una funzione per il mio sito Web in grado di stampare il contenuto della pagina come PDF. Ho provato alcune opzioni per questo, ma la migliore corrispondenza è stata wkhtmltopdf in quanto gestisce anche caratteri multilingue.

L'ho fatto funzionare sul mio server locale ma quando l'ho caricato su un server Web cloud per l'hosting ora mi sta dando il seguente errore

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.

Ho cambiato la politica di sicurezza in Web.config

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

Ma non funziona ancora

Test URL èhttp://www.noor.com.asp1-20.dfw1-2.websitestlink.com/articledetails.aspx?language=en-us&pageid=19&articleid=4

È possibile fare clic sul link per il download sul retro Questo collegamento Download Converti la particolare sezione della pagina Web in PDF. Funziona bene sul server locale ma non funziona per motivi di sicurezza sul server Web. Avevo cercato giorni per far funzionare il PDF e ora non funziona sul server Web. Ho provato altra opzione, ma per qualche motivo non stava convertendo l'arabo, stava stampando personaggi spazzatura solo per la versione araba di Page.

Si prega di avvisare cosa dovrei cambiare per farlo bene.

Ho sviluppato questo sito Web utilizzando ASP.NET 4.0 utilizzando C#

Codice che utilizzo per generare 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();
È stato utile?

Soluzione

Codice di lavoro: Ho risolto il problema chiamando PrintArticle.aspx da MainPage.aspx, quando l'utente stringe sul Lnkbtndownload Pulsante Link Chiamerà la pagina PrintHarticle.aspx (la pagina dell'articolo di stampa è una pagina semplice che mostra il titolo, la data e l'articolo dell'articolo) e passare l'HTML al codice sottostante che lo stamperà quindi come file 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();
    }

Sto passando altri parametri come stringa di query come articoloID, download, lingua ecc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top