doesuserHavePermissions 문제
-
10-12-2019 - |
문제
이 코드는 사이트 및 하위 사이트의 TreeView (웹 파트)를 만들고 관리자 계정에 완벽하게 작동하지만 일반 사용자는 아니지만 사용자가 액세스 할 수없는 경우에도 사이트 및 하위 사이트를 나열합니다 (그가 아닌)어떤 그룹의 구성원)과 그것이 가정하지 않습니다.
무엇을 잘못하고 있습니까?
spsecurity.runwithelevatedPrivileges를 사용해야합니까?
protected override void CreateChildControls()
{
TreeView listeTreeView = new TreeView();
listeTreeView.ID = "farmHierarchyViewer";
listeTreeView.ShowLines = true;
listeTreeView.EnableViewState = true;
this.Controls.Add(listeTreeView);
TreeNode node;
listeTreeView.Nodes.Clear();
SPWebApplication currentWebApplication = SPContext.Current.Site.WebApplication;
SPSiteCollection collSites = currentWebApplication.Sites;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
foreach (SPSite site in collSites)
{
site.CatchAccessDeniedException = false;
// Check if site collection != Mysite Host (54) et Mysite (21) and user access
if (site.RootWeb.WebTemplateId != 54 && site.RootWeb.WebTemplateId != 21
&& site.RootWeb.DoesUserHavePermissions(SPBasePermissions.Open))
{
try
{
node = new TreeNode();
TreeNode siteNode = node;
node = new TreeNode(site.RootWeb.Title, null, null, site.Url, "_self");
listeTreeView.Nodes.Add(node);
TreeNode parentNode = node;
foreach (SPWeb childWeb in site.RootWeb.Webs)
{
try
{
addWebs(childWeb, parentNode);
}
finally
{
childWeb.Dispose();
}
}
site.CatchAccessDeniedException = false;
}
finally
{
site.Dispose();
}
}
}
});
listeTreeView.CollapseAll();
}
void addWebs(SPWeb web, TreeNode parentNode)
{
// Check if site != Blog (9), != Search Center (50) and user access
if (web.WebTemplateId != 50 &&
web.DoesUserHavePermissions(web.CurrentUser.ToString(), SPBasePermissions.Open))
{
TreeNode node;
node = new TreeNode(web.Title, null, null, web.Url, "_self");
parentNode.ChildNodes.Add(node);
parentNode = node;
foreach (SPWeb childWeb in web.Webs)
{
try
{
addWebs(childWeb, parentNode);
}
finally
{
childWeb.Dispose();
}
}
}
}
. 해결책
CodeUserHavePermissions 코드의 상승 된 컨텍스트에 대한 점검을 할 수 있습니다 (따라서 현재 사용자가 액세스 할 수 있는지 확인하지 않지만 앱 풀 계정에있는 경우)
이 버전의 메소드를 사용하여 spcontext.current.web.currentuser의 loginname을 함수에 전달합니다. http://msdn.microsoft.com/en-us/library/ms441848.aspx
그래서
site.RootWeb.DoesUserHavePermissions(SPContext.Current.Web.CurrentUser.LoginName, SPBasePermissions.Open)
.
웹 오브젝트의 코스 에 조금 더 멀리 떨어져 있습니다
제휴하지 않습니다 sharepoint.stackexchange