We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Security Exception while saving as PDF

Hi everyone

Since our hosting-provider changed the security from full- to medium-trust we are experiencing some problems saving Files to PDF. We get the following error.

I already uploaded all neccessary TTF to the server and set the font-folder like this:

Aspose.Words.Fonts.FontSettings.SetFontsFolder("d:\client\public_html\upload\templates\fonts", False)

I’m looking forward to any Help I can get!

Server Error in ‘/’ Application.

Security Exception

*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: Request for the permission of type ‘System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

Source Error:*

Source File: d:\client\public_html\test\test.aspx.vb Line: 33

Stack Trace:*

[SecurityException: Request for the permission of type ‘System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +58
System.Environment.GetEnvironmentVariable(String variable) +66
xf9a9481c3f63a419.xed747ca236d86aa0.x0f5d18019ab06bc5() +13
xc23bef7190ca8f55.x9d888f53892d94df.x4a486311b726a005() +29
xc23bef7190ca8f55.x9d888f53892d94df.x34ef7a0ea5d7fab4() +156
xc23bef7190ca8f55.x9d888f53892d94df.get_x2445f4cefb3cff80() +75
xc23bef7190ca8f55.x9d888f53892d94df.xdc2247c8d4648ae8(String xa79a9f649c74f4a4, FontStyle x44ecfea61c937b8e) +11
xc23bef7190ca8f55.x26ee10d60756aeab.xdc2247c8d4648ae8(String xa79a9f649c74f4a4, FontStyle x44ecfea61c937b8e) +44
xc23bef7190ca8f55.x29ade4ed2382a039.xe42a11aae6b85740(String xa79a9f649c74f4a4, FontStyle x44ecfea61c937b8e, String x050683ee5a5f962b) +17
x59d6a4fc5007b7a4.xacc55eb1e4595209.xfeeb3de36742543a(x1d1dd20018fcde10 x26094932cf7a9139, x000f21cbda739311 x6f02b6a80bf6b36f) +76
x59d6a4fc5007b7a4.xbfac429e165a6a0d.xee5277c7de5be8e4(Char x3c4da2980d043c95) +46
x59d6a4fc5007b7a4.xbfac429e165a6a0d.x47f176deff0d42e2() +51
x59d6a4fc5007b7a4.x4f38812d0d5e7231.x4fb8d507f4b3c96e(Font x0078185e1040c523, String xb41faee6912a2313, x000f21cbda739311 xcb075c7088c3b520) +674
xf989f31a236ff98c.x08802e9e984cd3ee.CallHandlerDoText(Font font, String text, x000f21cbda739311 characterCategory) +20
xf989f31a236ff98c.x08802e9e984cd3ee.xc325f08e9c7ac384() +42
xf989f31a236ff98c.x08802e9e984cd3ee.xd22cb714335f8d2c(String xb41faee6912a2313, Font x26094932cf7a9139) +500
x59d6a4fc5007b7a4.x4f38812d0d5e7231…ctor(String text, x1d1dd20018fcde10 font, xacc55eb1e4595209 converter) +340
x59d6a4fc5007b7a4.x42f2a218ce59dafb.xbd6559e9bd341cd6(Inline xda5bf54deb817e37, Int32 x10aaa7cdfa38f254, Int32 x961016a387451f05) +197
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x4e33137198fdb9ca(Boolean xcd31b50c43a96e21) +63
x59d6a4fc5007b7a4.x487cdc969fefe3d6.x47f176deff0d42e2() +525
x59d6a4fc5007b7a4.xcde671c53995c411.xd9db07500873ae98(Document x3664041d21d73fdc, xdeb77ea37ad74c56 xdfde339da46db651) +317
Aspose.Words.Document.UpdatePageLayout() +24
Aspose.Words.Document.x410db0f4a89a6ef1(Boolean x24af0daafcd8fb8c) +29
xf989f31a236ff98c.x6c74398bceb133f8.xa2e0b7f7da663553(x8556eed81191af11 x5ac1382edb7bf2c2) +96
Aspose.Words.Document.xf381a641001e6830(Stream xcf18e5243f8d5fd3, String xafe2f3653ee64ebc, SaveOptions xc27f01f21f67608c) +125
Aspose.Words.Document.Save(String fileName, SaveOptions saveOptions) +150
Aspose.Words.Document.Save(String fileName, SaveFormat saveFormat) +28
test_test.Page_Load(Object sender, EventArgs e) in d:\client\public_html\test\test.aspx.vb:33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.test_test_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Version Information: Microsoft .NET Framework Version:2.0.50727.3655; ASP.NET Version:2.0.50727.3658

After some hours of research it seems as if the whole problem comes from some restrictions of the medium-trust-environment.

If I’m wrong with this, please let me know!

A question to the support-guys from ASPOSE: is there some custom policy of the trust-level that would make this whole thing work in a medium-trust-environment? What we want to do is open a Word-File, run some mail-merge and save the result as PDF.

Currently everything’s working except for the saving as PDF. We can save the document as DOC or DOCX, but not as PDF (and neither as Image).

Hi Andreas,

Thanks for your inquiry.

Aspose.Words rendering on a server will typically not work in an ASP.NET application configured to run under the Medium Trust level because it prohibits access to registry and limits access to the file system. To solve this issue you can need to specify your own folders filled with the appropriate fonts as suggested in the following article:

https://docs.aspose.com/words/net/specifying-truetype-fonts-location/

In addition are a few considerations when running on a shared server environment:

All Aspose .NET components are recommended to run with Full Trust permission set. This is because Aspose .NET component sometimes need to access registry settings and files located in places other than the virtual directory e.g. for reading fonts etc. Furthermore, Aspose.NET components are based on core .NET system classes, some of which also require Full Trust permission to run in some cases.

Internet Service Providers hosting multiple applications from different companies mostly enforce Medium Trust security level. In the case of .NET 2.0, such a security level may set the following constraints which could affect the ability of Aspose.Words to perform properly.

  • RegistryPermission is not available. This means you cannot access the registry, which is required to enumerate installed fonts when rendering documents.
  • FileIOPermission is restricted. This means you can only access files in your application’s virtual directory hierarchy. This potentially means fonts cannot be read during export.

For these reasons specified above, it is recommended that Aspose.Words is run on Full Trust permissions.

Best regards,

Hi Awais

Thanks for your reply.

Although I must confess that I’m a bit disappointed of the information you provided. Nothing you wrote was new to me after a day of research. It’s just a copy of information published on your website. So, to be honest, it wasn’t much of a help.

As mentioned in my initial post, we already set the font-directory (so this shouldn’t be the problem anymore). Both of your main points concerned this issue. So currently, I guess, it’s nothing about the font-types.

You also copied some very unspecific information from your website stating “some .NET system classes requre full trust in some cases”. This is extremely unspecific! Which classes in which cases? As we didn’t find this information online we hoped to get this information using ASPOSE-Support.

Now, as also mentioned in my posts, the client’s hosting-provider would be allright with adding some custom-policies to the trust-level. To successfully do this we would need to know what kind of permissions they had to set. Unfortunately you didn’t get into this…

I would still be very happy if you could dive deeper in my question.

This is, after beeing a ASPOSE-customer for 5 years now, my 4th support-question. I hoped to get better information…

Regards,

Andreas

Hi Andreas,

Thanks for the additional information. I would suggest you please refer to the "ASP.NET Full Trust Level" section of ASP.NET Trust Levels and Policy Files MSDN page. I hope, this helps.

Best regards,

Hi Awais

Thanks again for your reply.

Do you mean we could add ASPOSE to the fullTrustAssemblies like this?

As far as I can see, this only works for .NET 4.0 (so we would have to change the framework-version). But more important: could you help me find the right information for this? What version, publicKey, etc.?

I’m sorry for bothering you, but for me it’s the first time to dive into this. Until now we always had full-trust and had never to worry about all this stuff…

Regards,

Hi Andreas,

Thanks for your inquiry. According to the exception text “Request for the permission of type System.Security.Permissions.EnvironmentPermission”, it seems that Aspose.Words tries to access the restricted environment variables. Probably Aspose.Words tries to determine the OS version. We will consider catching this exception in the Aspose.Words code. We have logged this issue in our issue tracking system. Your request has also been linked to the appropriate issue (WORDSNET-10184) and you will be notified as soon as it is worked out. Sorry for the inconvenience. In the meantime, please try to grant the access to the environment variables. I hope, this helps.

Best regards,

Hi Andreas,

Thanks for being patient. Just checking to see if you managed to resolve this issue on your end; if yes, could you please share what was the cause of this issue and how did you fix it? Regarding WORDSNET-10184, we initially suspected that the potential cause of this problem would be Environment.OSVersion property but later it turned out that by default accessing Environment.OSVersion is allowed under medium trust. Unfortunately, we are not able to spot exact piece of code in Aspose.Words code base which could cause this exception. Could you please provide us more details which will definitely help us get to the bottom of this problem.

Best regards,

Hi Andreas,

Thanks for being patient. It is to update you that we cannot analyze the issue further as we had not received further input from your end. We have now closed WORDSNET-10184 with status “not a bug”. Please try upgrading to the latest version.

We apologize for any inconvenience.

Best regards,

awais.hafeez:

Could you please provide us more details which will definitely help us get to the bottom of this problem.

We didn’t find the time to further investigate on this toppic. Our final solution was changing the hosting-provider… Not what one would call a real solution, but the first goal was to get the thing to work again.

Thanks for your help and your investigations.

Regards,

Hi Andreas,

Thanks for your inquiry. Please let us know any time you have any further queries.

Best regards,