以下にリストされている2つの方法では、なぜ同じセキュリティトリミングが行われないのでしょうか。
期待される結果:どちらの方法でも、現在のサイトコレクション のすべてのコンテンツにフルアクセスできます
実際の結果: 方法1を使用すると、セキュリティのトリミングが発生します
方法2は、他のWebからコンテンツを取得するために適切に機能しますが、方法1は機能しません。
どちらの方法でも、匿名モードでWeb全体にアクセスでき、どちらもサイト管理者アカウントで機能します。
違いは、階層マネージャー、承認者、編集者にあります。方法1では、Web間で管理者アクセスを許可しません。
方法#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
});