2009-02-19 19 views
1

我想知道爲什麼下面列出的兩種方法不提供相同的安全修整。在MOSS發佈站點使用提升權限運行的方法

預期結果:兩種方法給當前網站集

實際結果完全訪問所有內容:安全修整,使用方法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 
    }); 
+0

問題在哪裏? – Tundey 2009-02-19 17:17:06

回答

1

RunWithElevatedPrivileges提供兩個獨立privledges。首先是它將用戶的Windows身份提升到AppPool帳戶,其次是它還將身份提升到SharePoint \ System帳戶,該帳戶是一個內置的安全帳戶,提供完全控制(在SharePoint意義上)。內部SharePoint帳戶用於構建SP對象(如SPSite)。

所以基本上它取決於你如何構建你的代碼,以及什麼時候你的對象會影響到這些權限的工作方式。