【发布时间】:2017-08-11 19:51:02
【问题描述】:
我想知道为什么下面列出的两种方法不能提供相同的安全调整。
预期结果:这两种方法都可以完全访问当前网站集中的所有内容
实际结果:使用方法#1时发生安全修整
方法 #2 可正常用于从其他网站检索内容,但方法 #1 不能。
这两种方法都以匿名模式提供跨网络访问,并且都适用于站点管理员帐户。
层级管理者、审批者和编辑者的区别在于。方法 #1 不提供跨网络的管理员访问权限。
方法#1
using (SystemOperation op = new SystemOperation())
{
//Do an operation that requires retrieving across webs
}
public class SystemOperation : IDisposable
{
private WindowsImpersonationContext ctx;
public SystemOperation()
{
if (!WindowsIdentity.GetCurrent().IsSystem)
{
ctx = WindowsIdentity.Impersonate(System.IntPtr.Zero);
}
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool all)
{
if (ctx != null)
{
ctx.Undo();
}
}
}
方法#2:
Microsoft.Sharepoint.SPSecurity.RunWithElevatedPrivileges(delegate()
{
//Do an operation that requires retrieving across webs
});
【问题讨论】:
-
对不起,我没有回答您的问题,但我很好奇您为什么要使用方法 1?此外,代码格式似乎在您的问题中搞砸了。
-
您需要 #1 的原因是因为 RunWithElevatedPrivileges 并非在所有情况下都有效,例如访问配置文件管理器。
-
SPSite.SystemAccount.UserToken(以及使用此令牌的新 SPSite())方法怎么样?这如何适应?
-
bzlm - 一个对比 RWEP 和 SPUserToken 的例子。 tinyurl.com/cdmvxe,这篇文章非常悲观,因为根据 MS RWEP “应该谨慎使用。你不应该为低权限的人暴露直接的、不受控制的机制来规避授予他们的权限”。
标签: sharepoint sharepoint-2007 moss