我想知道为什么下面列出的两种方法没有提供相同的安全调整。
预期结果: 两种方法都可以完全访问当前网站集中的所有内容
实际结果: 使用方法 #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
});