使用 RunWithElevatedPrivileges 时访问被拒绝?
我希望普通用户可以访问 Mysite 根站点中的“用户信息列表”。我正在使用“RunWithElevatedPrivileges”方法。仍然抛出访问被拒绝错误。例如,我的网站的根网站集是“http://network.test.com”。用户想要评估用户信息列出此网站集。他如何才能访问它?
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
{
ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
UserProfile up = null;
//get current user's profile (visitor)
if (upm.UserExists(SPContext.Current.Web.CurrentUser.LoginName))
{
up =upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
SPWeb web = SPContext.Current.Web;
SPList userInformationList = web.Lists["User Information List"];
I want regular user can access the "User Information List" in Mysite root site. I am using "RunWithElevatedPrivileges" method. Still throwing access denied error. per example my root site collection for mysite is "http://network.test.com". the user want assess userinformation list this site collection. How can he access that?
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite site = new SPSite(SPContext.Current.Web.Site.ID))
{
ServerContext sc = ServerContext.Current;
UserProfileManager upm = new UserProfileManager(sc);
UserProfile up = null;
//get current user's profile (visitor)
if (upm.UserExists(SPContext.Current.Web.CurrentUser.LoginName))
{
up =upm.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
SPWeb web = SPContext.Current.Web;
SPList userInformationList = web.Lists["User Information List"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
SPContext.Current
在RunWithelevatedPrivileges
提升的上下文之外运行。有关详细信息,请参阅此博文。SPContext.Current
runs outside theRunWithelevatedPrivileges
elevated context. For more info see this blog post.您将 SPWeb 设置为 SPContext.Current.Web,这没有提升的权限。只有从委托内部创建的 SPSites 创建的 SPWeb 才会被提升。
所以你需要替换
为
You're setting your SPWeb to SPContext.Current.Web, this doesn't have elevated privileges. Only SPWebs created from SPSites created inside the delegate are elevated.
So you need to replace
with
您将 SPWeb 设置为 SPContext.Current.Web,这没有提升的权限。
请参阅此帖子:
You're setting your SPWeb to SPContext.Current.Web this doesn't have elevated privileges.
Refer this post: