Monday, December 7, 2009

Infopath System.Security. Permissions.EnvironmentPermission Fulltrust

Hey All,

When I tried to get current user in code behind in the infopath form, the following security exception occurred. The solution is we need to set Full trust for the Form.

Code used: nav.SelectSingleNode("//my:Myfield", NamespaceManager).SetValue(System.Environment.UserName);

Exception Message:
Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.Environment.get_UserName() at ItemCreation.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.<>c__DisplayClass8.b__1() at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass6.b__0(Object sender, LoadingEventArgs e) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.<>c__DisplayClass34.b__30() at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d) at Microsoft.Office.InfoPath.Server.SolutionLifetime.FormEventsHost.FireLoadingEvent(Document document, Dictionary`2 inputParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.PerformOnLoadEvent(Dictionary`2 intputParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.LoadSolutionAndDocument(HttpContext context, Solution solution, DocumentMetaInformation documentMetaInformation, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.OpenDocumentWithSolution(HttpContext context, SPSite contextSite, Solution solution, DocumentMetaInformation documentMetaInformation, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.NewFromSolution(HttpContext context, SPSite contextSite, Solution solution, DocumentMetaInformation documentMetaInformation, Boolean disableFirstRequestOptization, OnInitializeCallback onInitializeCallback, OpenParameters openParameters) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.DataBindInternal(SolutionMetaInformation solutionMetaInformation, DocumentMetaInformation documentMetaInformation, String absoluteSolutionLocation, Boolean hasCloseHandler, Document& document) at Microsoft.Office.InfoPath.Server.Controls.FormServerPage.InitializeRenderInLine(SolutionMetaInformation solutionMetaInformation, DocumentMetaInformation documentMetaInformation, String absoluteSolutionLocation) at Microsoft.Office.InfoPath.Server.Controls.FormServerPage.NewEditingSession(SPSite contextSite, FormServerPageQueryParameters queryParameters) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.StartNewEditingSession() at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.EnsureDocument(EventLogStart eventLogStart) at Microsoft.Office.InfoPath.Server.Controls.XmlFormView.<>c__DisplayClass3.b__1() at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock) The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.EnvironmentPermission The first permission that failed was: version="1" Read="UserName"/> The demand was for: version="1" Read="UserName"/> The granted set of the failing assembly was: version="1"> version="1" Flags="Execution"/> version="1" PublicKeyBlob="0024000004800000940000000602000000240000525341310
00400000100010083EF9CF1283A631F1C2513A36EA356E01870A92F21E61D5D53
1420B2C3905A6E3F8A0BD9E2BFAD3EAB3362877D233232ED1AE4836A1C51EAA7
717A16047A0F6F6E589F8689BCC5A15A20211252DB101B889228C5E15A3D49DC
2E112650853F16A85DD01652057E5D2CE7A41B01AA56576FFED4B4567FD8367
EE777C222C590E6"
Name="ItemCreation" AssemblyVersion="1.0.3628.18207"/> version="1" Url="file:///c:/inetpub/wwwroot/"/> version="1" Zone="MyComputer"/> version="1" Level="Minimal"/> version="1" Connections="True"/> The assembly or AppDomain that failed was: ItemCreation, Version=1.0.3628.18207, Culture=neutral, PublicKeyToken=f4d1ad1bba384fc7 The method that caused the failure was: Void FormEvents_Loading(System.Object, Microsoft.Office.InfoPath.LoadingEventArgs) The Zone of the assembly that failed was: MyComputer The Url of the assembly that failed was: file:///c:/inetpub/wwwroot/

How to set Permission: In Tools -> Form Options -> Security & trust -> Full Trust & Publish



Hope it Helpz

Thanks & Regards
Fauzi ~ 4Z

No comments: