WSS3 Elevation of Privilege 替代 用户身份模拟Impersonate 进行权限提升

正文:
WSS3 中的 Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges 替代 Impersonate 进行权限提升.
好处就是根本不需要在配置文件写些什么用户名密码, 省了麻烦, 加了一定密码泄漏安全, 但是也增加了不安全代码的后门.
RunWithElevatedPrivileges 使用的是你IIS Application的进程池帐户,所以注意安全,嘿嘿.
 
SPSecurity.RunWithElevatedPrivileges(delegate()
{
    // 用系统帐户做操作
});
SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
    {//注意要new一个, 用SPContext.Current.Site的话,那就是当前帐户的安全级别
       //用系统帐户操作这个site
    }
});
 
照抄MSDN的代码例子:
SPWeb web = SPContext.Current.Web;
SPUser user = web.CurrentUser; // the calling user
 
     
   // Uses the SHAREPOINT\system creds with the SPUser's identity reference of user
SPSecurity.RunWithElevatedPrivileges(delegate() {
  // Gets a new security context using SHAREPOINT\system
  using (SPSite site = new SPSite(this.Page.Request.Url.ToString())) {
    using (SPWeb thisWeb = site.OpenWeb()) {
      thisWeb.AllowUnsafeUpdates = true;
      SPList theList = thisWeb.Lists[listName];
      SPListItem record = theList.Items.Add();
      record["User"] = user; // calling user
      record.Update(); // uses SHAREPOINT\system
    }
  }
});
类别: SharePoint
发布日期: 2007-6-14 20:43
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值