简体   繁体   English

部署时“该程序集不允许部分受信任的呼叫者”

[英]“That assembly does not allow partially trusted callers” on deployment

I have been trying to ExportPDF using the iTextSharp dll file. 我一直在尝试使用iTextSharp dll文件ExportPDF The code works fine locally but gives following error. 该代码在本地可以正常工作,但会出现以下错误。

{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)"

This is ExportPDF(..) 这是ExportPDF(..)

[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 is how I am calling this method from JavaScript file 这就是我从JavaScript文件调用此方法的方式

  function SaveToPDF() { $('div[id$=divStockoutPdf] > div[id$=divItems]').html($('#divStockoutItems').html()); //remove the delete button from pdf $('div[id$=divStockoutPdf] > div[id$=divItems] table td:last').remove(); $('div[id$=divStockoutPdf] > div[id$=divItems] table th:last').remove(); var IssuedToemailID = $('#txtStockoutIssuedToEmail').val(); var contents = $('#divStockoutPdf').html(); //$('#divStockoutItems').html(); contents = contents.replace(/>/g, '&gt;'); contents = contents.replace(/</g, '&lt;'); $.ajax({ type: "POST", url: "WebMethods.aspx/ExportToPDF", data: "{'html': '" + contents + "','IssuedToemailID': '" + IssuedToemailID + "' }", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d == 1) { $('#btnCloseSignaure').click(); UpdateStockout(); } else alert("Internal Error. Kindly contact support team. Error at SaveToPDF"); }, error: function (er) { alert(er.error) } }); } 

I have tried all the solutions available online but nothing seems to be working or I might not been able to implement the solution properly. 我已经尝试了所有在线可用的解决方案,但似乎没有任何效果,或者我可能无法正确实施该解决方案。 I have followed this 我已经遵循

looks like you explicitly need to make ISharpText assembly to allow partially trusted users. 看起来您明确需要进行ISharpText程序集以允许部分受信任的用户。 Below link might help : 以下链接可能有帮助:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM