Click here to Skip to main content
15,887,379 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am facing an Security Exception issue.
I am trying to export an pdf file but I am getting this error:
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: That assembly
does not allow partially trusted callers.

Now I am changing the web.config file by setting ASP.NET hosting trust level
but still it is not working:I am getting this Parser error:
Parser Error Message: This configuration section cannot be used at
this path. This happens when the site administrator has locked access
to this section using <location allowOverride="false"> from an
inherited configuration file.

This the code I am adding in web.config file:

XML
<location allowOverride="true">
    <system.web>
      <securityPolicy>
       <trustLevel name="Full" policyFile="internal" />
      </securityPolicy>
      <trust level="Full" originUrl="" />
     </system.web>
   </location>


And I have also tried with these trust level one by one:
XML
<trustLevel name="High" policyFile="web_hightrust.config" />
<trustLevel name="Medium" policyFile="web_mediumtrust.config" />
<trustLevel name="Low" policyFile="web_lowtrust.config" />
<trustLevel name="Minimal" policyFile="web_minimaltrust.config" />
<trustLevel name="Custom" policyFile="web_CustomTrust.config" />



But still it is not working
Please can help fixing this.By the way I am hosted in Godaddy.
Posted
Updated 15-May-20 9:02am
v2
Comments
Rockstar_ 4-Jun-13 6:11am    
Please give full access to the folder which u r using for PDF files...
El Dev 4-Jun-13 6:15am    
I am not using any folder.This is the my code to export the pdf.

protected void ExportPDF_Onclick(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=OrderDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
this.Page.RenderControl(tw);
StringReader sr = new StringReader(sw.ToString());
Document Orderpdf = new Document(PageSize.A4, 10f, 10f, 0f, 0.0f);
HTMLWorker htmlparser = new HTMLWorker(Orderpdf);
PdfWriter.GetInstance(Orderpdf, Response.OutputStream);
Orderpdf.Open();
htmlparser.Parse(sr);
Orderpdf.Close();
Response.Write(Orderpdf);

Response.End();

}
I dont need to upload this file.

1 solution

"This happens when the site administrator has locked access
to this section using <location allowOverride="false"> from an
inherited configuration file."

If you are the administrator of that web server, find that file with that setting and change that first.
If you are not the administrator, find him and tell him.
 
Share this answer
 
Comments
El Dev 4-Jun-13 6:56am    
Bernhard,I am the admin of the web server.Please need some idea from u.

What I am doing is export a pdf file for more than one order detail but the the name of the pdf file is not changing but the content change depend of the order selected by the user it is called OrderDetails.pdf
Now my kestion is Do I need to upload that file in live also.Because in my local I can export and my local system allow me to open that file.But not in live.
Bernhard Hiller 4-Jun-13 9:05am    
"By the way I am hosted in Godaddy." - "I am the admin of the web server" : which one is right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900