部署时“该程序集不允许部分信任的调用者”

时间:2018-02-05 04:01:30

标签: javascript c# .net itext

我一直在尝试Controller @CrossOrigin(origins = "http://localhost:4200") public class QuestionController { private final SimpMessagingTemplate template; @Autowired QuestionController(SimpMessagingTemplate template){ this.template = template; } @MessageMapping("/send/message") public void onReceivedMessage(String message){ System.out.println("received message for question mapping for the controller"); this.template.convertAndSend( "/chat", new SimpleDateFormat("HH:mm:ss").format(new Date())+ message); } 使用iTextSharp dll文件。代码在本地工作正常,但会出现以下错误。

ExportPDF

这是{Message: "That assembly does not allow partially trusted callers.",…} ExceptionType : "System.Security.SecurityException" Message : "That assembly does not allow partially trusted callers." StackTrace : " at Admin_WebMethods.ExportToPDF(String html, String IssuedToemailID)"

ExportPDF(..)

这是我从JavaScript文件

调用此方法的方法

[WebMethod]
    public static int ExportToPDF(string html, string IssuedToemailID)
    {
        int status = 0;
        try
        {
            string FileName = "Invoice_" + DateTime.Now.ToString("M_dd_yyyy_H_M_s");

            html = html.Replace(">", ">");
            html = html.Replace("&lt;", "<");
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + FileName + ".pdf");

            StringReader sr = new StringReader(html);
            Document pdfDoc = new Document(PageSize.A4, 10f, 2f, 2f, 2f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            //PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
            string path = @"~\PdfGeneration\" + FileName + ".pdf";
            PdfWriter.GetInstance(pdfDoc, new FileStream(HttpContext.Current.Server.MapPath(path), FileMode.Create));
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            HttpContext.Current.ApplicationInstance.CompleteRequest();

            // send email here                     
            sendemail(path, IssuedToemailID);

            status = 1;
        }
        catch (Exception exp)
        {
            status = 0;
        }
        return status;

    }

我已尝试过在线提供的所有解决方案,但似乎没有任何效果,或者我可能无法正确实施解决方案。我关注了this

1 个答案:

答案 0 :(得分:1)

看起来您明确需要使ISharpText程序集允许部分受信任的用户。以下链接可能有所帮助:

https://www.aspsnippets.com/Articles/ASPNet-iTextSharp-SystemSecuritySecurityException-That-assembly-does-not-allow-partially-trusted-callers.aspx