迭代“我的网站”网站集时出现访问被拒绝错误?
我正在为他登录的用户迭代当前的共享点网站集,并显示他已阅读并为网站贡献权限的网站名称,这工作正常。
同时,我必须迭代具有读取和贡献权限的“我的网站”网站集。当我在 Mysites 网站集子网站中执行 foreach (SPWeb jweb in esite.AllWebs) 时。它抛出一个错误“访问被拒绝”。
但是当我在浏览器中输入网址时,他可以看到这些网站吗?我在 SPSecurity.RunWithElevatedPrivileges 中添加了代码,但仍然无法访问这些网站。这个 _layout 文件夹页面和我只在 aspx 页面中编写代码。
如何解决这个问题?
SPSite site = SPContext.Current.Web.Site; // http://committees.test.com
SPUser user = SPContext.Current.Web.CurrentUser;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite esite = new SPSite(site.ID))
{
Control cont5 = this.LoadControl("/_CONTROLTEMPLATES/ALERTUC/uc5.ascx");
cont5.ID = "GLOBE";
RadioButtonList glbrbl = (RadioButtonList)cont5.FindControl("RBList5");
try
{
glbrbl.SelectedValue = user.Notes.ToString();
}
catch (Exception) { }
GlobalPnl.Controls.Add(cont5);
foreach (SPWeb jweb in esite.AllWebs)
{
if (!jweb.IsRootWeb)
{
if (jweb.GetSubwebsForCurrentUser().Count != 0)
{
if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID)
{
getsubweb(jweb, Panel1, user);
}
}
}
}
}//using
using (SPSite esite = new SPSite("http://mysitesdev.test.com/groups/grp"))
{
foreach (SPWeb jweb in esite.AllWebs) //**Access Denied**
{
if (!jweb.IsRootWeb)
{
if (jweb.GetSubwebsForCurrentUser().Count != 0)
{
if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID)
{
getsubweb(jweb, Panel1, user);
}
}
}
}
}
});
I was iterating current sharepoint site collection for the user which he logged into, and displaying sites names which he has read and contribute permission to sites and this is working fine.
At the same time I have to iterate Mysites site collection where has read and contribute permission. When I do foreach (SPWeb jweb in esite.AllWebs) in Mysites site collection sub sites. It is throwing an error "ACCESS DENIED".
But when I typed url in on browser he can see those sites?. I added code in SPSecurity.RunWithElevatedPrivileges still unable to access those site. This _layout folder page and I written code in aspx page only.
How to resolve this?
SPSite site = SPContext.Current.Web.Site; // http://committees.test.com
SPUser user = SPContext.Current.Web.CurrentUser;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite esite = new SPSite(site.ID))
{
Control cont5 = this.LoadControl("/_CONTROLTEMPLATES/ALERTUC/uc5.ascx");
cont5.ID = "GLOBE";
RadioButtonList glbrbl = (RadioButtonList)cont5.FindControl("RBList5");
try
{
glbrbl.SelectedValue = user.Notes.ToString();
}
catch (Exception) { }
GlobalPnl.Controls.Add(cont5);
foreach (SPWeb jweb in esite.AllWebs)
{
if (!jweb.IsRootWeb)
{
if (jweb.GetSubwebsForCurrentUser().Count != 0)
{
if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID)
{
getsubweb(jweb, Panel1, user);
}
}
}
}
}//using
using (SPSite esite = new SPSite("http://mysitesdev.test.com/groups/grp"))
{
foreach (SPWeb jweb in esite.AllWebs) //**Access Denied**
{
if (!jweb.IsRootWeb)
{
if (jweb.GetSubwebsForCurrentUser().Count != 0)
{
if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID)
{
getsubweb(jweb, Panel1, user);
}
}
}
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的评论,RunWithElevatedPrivileges 正在以
http://committees.test.com
上的应用程序池的身份运行,但正在尝试访问http://mysitesdev 上的网站集.test.com
。两个 Web 应用程序是否使用相同的应用程序池标识?除非http://committees.test.com
上的应用程序池身份具有http://mysitesdev.test.com/groups/grp
的权限,否则我希望访问被拒绝错误。According to your comments, RunWithElevatedPrivileges is running in the identity of the Application Pool on
http://committees.test.com
, but is trying to access a site collection onhttp://mysitesdev.test.com
. Are both web applications using the same Application Pool identity? Unless the Application Pool identity onhttp://committees.test.com
has permissions onhttp://mysitesdev.test.com/groups/grp
, I would expect an Access Denied error.您正在以提升的权限运行每个外部运行,因此它仍然在用户的安全上下文中运行。
You are running your for each outside the run with elevated privileges, so it is still running in the security context of the user.