• 权限提升


    什么时候适合使用权限提升;一般的用户如游客(everyone),我们会赋予的read的权限,read的权限可能能够查看sitecontent,但是不能操作。如要涉及到操作可能就需要使用到权限替身了。此外,如果该网站如果读的是跟网站的sitecontent,可能游客也没有权限查看到,这时候也需要使用到权限提升。当然,究竟什么时候使用权限替身,最好的办法就是用目标用户的身份登录,看能否查看该页面,若不能,则去提升其权限。

                SPSecurity.RunWithElevatedPrivileges(delegate()//虚拟管理员,否则其他用户访问没有权限
                {
                    using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                    {
                        using (SPWeb myweb = site.OpenWeb())
                        {
                            SPList list = myweb.Lists[ListNames.BBSScoreManage];
                            SPQuery spquery = new SPQuery();
                            string querystring = string.Format(@"
                                                              <Where>
                                                                  <Eq>
                                                                     <FieldRef Name='Title' />
                                                                     <Value Type='Text'>{0}</Value>
                                                                  </Eq>
                                                               </Where>
                                                            ", userName);
                            SPListItemCollection items = list.GetItems(spquery);
                            SPListItem item = items[0];
                            if (items.Count > 0 && Convert.ToInt32(item["Score"]) > score)
                            {
                                int resultScore = Convert.ToInt32(item["Score"]) + score;
                                item["Score"] = resultScore;
                                item.Update();
                            }
                        }
                    }
                });

  • 相关阅读:
    EPUB书籍阅读器插件分享
    网页端压缩解压缩插件JSZIP库的使用
    让编辑器支持word的复制黏贴,支持截屏的黏贴
    MYSQL GTID position
    Google SRE
    MySQL大小写敏感
    SpringMVC model 多余字段 忽略
    To B Vs To C
    滴滴 CTO 架构师 业务 技术 战役 时间 赛跑 超前 设计
    Spring Boot 集成Swagger
  • 原文地址:https://www.cnblogs.com/dearbear/p/3474520.html
Copyright © 2020-2023  润新知