none
Erro de Security Exception na WebParts RRS feed

  • Pergunta

  • Tenho uma WebParts com o seguinte código para Exportar PDF:

     GridView1.DataSource = dt;

            GridView1.DataBind();

            HtmlForm form = new HtmlForm();

            form.Controls.Add(GridView1);

            StringWriter sw = new StringWriter();

            HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);

            form.Controls[0].RenderControl(hTextWriter);

            string html = sw.ToString();

            string htmlDisplayText = @"<table width='100%'>" +

                "<tr>" +

                    "<td width='10%' rowspan='3'><img src='http://amsterda:8033/img/logo70.png' width='70' height='67'>" +

                        "</td>" +

                    "<td width='65%' rowspan='3' valign='top'><div align='center'>" +

                      "<p><font face='Georgia, Times New Roman, Times, serif'>REQUISI&Ccedil;&Atilde;O " +

                      "PARA ALMOXARIFADO</font></p><br>" +

                      "<p style='font-family: Arial, Helvetica, sans-serif; font-size: medium'><font face='Georgia, Times New Roman, Times, serif'>" + Session["Obra"] + " <br> " + Session["CodPrj"] + "  </font></p>" +

                    "</div></td>" +

                    "<td width='25%' valign='top'><p align='right' style='font-size: small'><font face='Georgia, Times New Roman, Times, serif'>Data " + 

                          "Exporta&ccedil;&atilde;o: " + System.DateTime.Now.ToString() + " </font></p>" +

                    "</td>" +

                "</tr>" +

                "<tr>" +

                  "<td valign='top'><div align='right'><p style='font-size: small'><font face='Georgia, Times New Roman, Times, serif'></font><p/></div></td>" +

                "</tr>" +

                "<tr>" +

                   "<td valign='top'><div align='right'><p style='font-size: small'><font face='Georgia, Times New Roman, Times, serif'>Requisitante: " + Session["Usuario"] + "</font><p/></div></td>" +

                "</tr>" +

            "</table> " +

            "{EMPLOYEETABLE}";

            htmlDisplayText = htmlDisplayText.Replace("{EMPLOYEETABLE}", html);

            Document document = new Document(PageSize.A4.Rotate(),7f, 7f, 7f, 0f);

            MemoryStream ms = new MemoryStream();

            PdfWriter writer = PdfWriter.GetInstance(document, ms);

            StringReader se = new StringReader(htmlDisplayText);

            HTMLWorker obj = new HTMLWorker(document);

            document.Open();

            obj.Parse(se);

            // step 5: we close the document

            document.Close();

            Response.Clear();

            Response.AddHeader("content-disposition", "attachment; filename= '" + "SA-" + System.DateTime.Now.ToString() + "'.pdf");

            Response.ContentType = "application/pdf";

            Response.Buffer = true;

            Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);

            Response.OutputStream.Flush();

            Response.End();

     

    Mas está dando esse erro:

     System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Alguém sabe como resolver isso?

    Valeu!!!


    Junior Santana
    quinta-feira, 5 de janeiro de 2012 10:45

Todas as Respostas

  • Junior, tenta colocar esta tag dentro da section "system.web" no web.config:

    <trust level="Full" />
    

    Abraços.


    Leandro Faria
    PMP, CSM, ITIL, FCE, MCITP, MCPD, MCTS, MCT
    MCITP e MCPD SharePoint 2010
    http://leandrofaria.com.br/blog
    http://br.linkedin.com/in/leandrofaria
    http://twitter.com/lhfaria
    quinta-feira, 5 de janeiro de 2012 12:51