Sharepoint Web部件安全性异常

Sharepoint Web部件安全性异常,sharepoint,sharepoint-2007,web-parts,Sharepoint,Sharepoint 2007,Web Parts,我有一个自定义sharepoint web部件引发以下异常: System.Security.SecurityException: Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429

我有一个自定义sharepoint web部件引发以下异常:

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

我的理论是Sharepoint没有运行web部件的信任级别,但我很难找出如何调试这个问题。有没有人有过调试这种东西的经验?

您有几种选择。首先是将程序集安装到GAC中。然后它将获得完全信任,但您必须将其安装在GAC中,并对其进行强名称命名,等等。第二个选项是进入web.config并将其添加到受信任列表中。并将帮助你走上这条道路

第三个选项是将程序集放到C:\inetpub\wwwroot\wss\VirtualDirectories[port]\u app\u bin文件夹中。这在全局SharePoint配置中设置为完全信任其中的任何程序集。您可能想先尝试一下,看看它是否有帮助,如果有帮助,请使用其他两种方法之一(因为从技术上讲,这是一种未记录的特性,可以更改)

编辑:好的,有几件事你可以试试。尝试提高总体信任级别,如图所示。基本上寻找:

如果这样做有效,则表明您依赖的是不受信任的DLL。请注意,您不希望将其保留为完全信任级别,因为这意味着任何Web部件都具有完全信任

这有用吗?

太疯狂了。 我无法在web部件中执行以下行:

using (SPSite site = new SPSite(parentWebUrl))
但是,我可以不使用web部件来执行它

它引发了一个类似的异常,尽管DLL在GAC中,但添加到safecontrols中的是

Exception: SecurityException
Message: Request failed.
Action: System.Security.Permissions.SecurityAction.Demand
Some stack trace:
    at Microsoft.SharePoint.SPWeb.SPWebConstructor(SPSite site, String url, Boolean bExactWebUrl, SPRequest request)
    at Microsoft.SharePoint.SPWeb..ctor(SPSite site, String url, Boolean bExactWebUrl)
    at Microsoft.SharePoint.SPSite.OpenWeb()
    at ....
它还说

((System.Security.SecurityException)($exception)).Demanded
((System.Security.SecurityException)($exception)).DenySetInstance
((System.Security.SecurityException)($exception)).FailedAssemblyInfo
((System.Security.SecurityException)($exception)).FirstPermissionThatFailed
((System.Security.SecurityException)($exception)).GrantedSet
抛出了一个异常

这有什么问题

解决方案 事实证明,像THES这样的错误很多次都是因为Web部件构造函数中发生了各种操作。您几乎无法在那里与SharePoint对象模型交互


将代码移动到其他可以工作的地方。我把代码移到CreateChildControls上,它成功了。

打开dll似乎是唯一有效的方法——尽管它确实有效。