Wednesday, November 25, 2009

Pdf generation and Partial Trust problem

There do exist several issues with trust level when using any dll for pdf creation. I first tried microsoft reporting but it requires full trust. Then I opted for itextSharp but again I run into a problem of full trust. This article

http://instantdevelopment.blogspot.com/2009/10/itextsharp-pdf-rendering-in-medium.html really help me out to find a way to make the assembly work under medium trust.

 

Also You can check the current trust level using this code snipped.

 

AspNetHostingPermissionLevel GetCurrentTrustLevel()

    {

        foreach (AspNetHostingPermissionLevel trustLevel in

        new AspNetHostingPermissionLevel[] {

AspNetHostingPermissionLevel.Unrestricted,

AspNetHostingPermissionLevel.High,

AspNetHostingPermissionLevel.Medium,

AspNetHostingPermissionLevel.Low,

AspNetHostingPermissionLevel.Minimal

})

        {

            try

            {

                new AspNetHostingPermission(trustLevel).Demand();

            }

            catch (System.Security.SecurityException)

            {

                continue;

            }

            return trustLevel;

        }

        return AspNetHostingPermissionLevel.None;

    }

 

No comments: