I have a custom sharepoint web part that is throwing the following exception:
System.Security.SecurityException: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed. at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Waverly.SharePoint.Features.WebParts.SearchesListWebPart.Render(HtmlTextWriter writer) The action that failed was: Demand The type of the first permission that failed was: Microsoft.SharePoint.Security.SharePointPermission The Zone of the assembly that failed was: MyComputer
My theory is that Sharepoint does not have the trust level to run the web part but I’m having difficulty figuring out how to debug this problem. Anyone have any experience debugging something like this?
There are several options you have. The first is to install your assembly into the GAC. It will then get full trust, but you have to install it in the GAC, strong name it, etc. The second option is to go into the web.config and add it to the trusted list. This article and this one will help you get down that path.
The third option is to drop your assembly in the C:\inetpub\wwwroot\wss\VirtualDirectories[port]_app_bin folder. This is set in the global SharePoint config to fully trust any assemblies in there. You might want to try that first just to see if it helps, and if so, use one of the other two methods (since technically that’s an undocumented feature and could be changed)
EDIT: Ok, there’s a couple of things you can try. Try bumping up the overall trust level as shown in this article. Basically look for:
<trust level=’Full’ originUrl=” />
If that works, then it indicates that you are relying on a DLL that isn’t trusted. Note that you don’t want to leave it with trust level Full, since that means any webpart has full trust.
Does that help?