仅返回用户有权访问的站点列表 [英] Return only the list of sites to which user has access

查看:55
本文介绍了仅返回用户有权访问的站点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码并尝试仅使用用户有权访问的站点列表填充下拉列表。当用户访问该页面时,他们会看到所有站点,当他们点击他们无法访问的站点时,会提示
,并请求访问该站点的页面。如何修改代码以仅显示用户有权限的网站列表



  protected override void OnPreRender (EventArgs e)

        {

            string permission = string.Empty;

            ddSites.Items.Clear();


            SPSecurity.RunWithElevatedPrivileges(委托()

                 &NBSP ;    {


               &NBSP ;          using(SPSite siteColl = new SPSite(" http: // ******* / "))

                           {

       &NBSP ;                     若(siteColl.RootWeb.DoesUserHavePermissions (SPContext.Current.Web.CurrentUser.LoginName,
SPBasePermissions.Open))

             &NB属;                 {


                                    {

                    &NBSP ;                的foreach(的SPWeb oWeb在siteColl.RootWeb.GetSubwebsForCurrentUser())

              &NBSP ;                       {

                    &NBSP ;                     ddSites.Items.Insert(0,
新的ListItem(QUOT;请选择一个站点"," 0"));

                                           的foreach(在siteColl.AllWebs的SPWeb
织物)

              &NBSP ;                        &NBSP ;  {

                    &NBSP ;                        


                  &NBSP ;                        &NBSP ; 
{


                                                   
ddSites.Items.Add(新列表项(web.Title,web.ID.ToString()));


                                               
}

                  &NBSP ;                        &NBSP ; 
终于

                  &NBSP ;                        &NBSP ; 
{

                  &NBSP ;                        &NBSP ;     
web.Dispose();

                                               
}

                  &NBSP ;                       }


                                          如果(!selectedSiteGuid.Equals(Guid.Empty))

                                            {

                    &NBSP ;                        
ddSites.Items.FindByValue(selectedSiteGuid.ToString())

            &NBSP ;                        &NBSP ;       
中选择= TRUE;


               &NBSP ;                        &NBSP ;   


                                           }

                    &NBSP ;                 }

                    &NBSP ;             }

                    &NBSP ;         }

                    &NBSP ;     }

                    &NBSP ; });
$
        }





IPW

解决方案

< blockquote>

我没有在下拉列表中执行此操作,而是使用页面上的"搜索结果"Web部件定期执行此操作。 而不是遍历所有站点尝试以编程方式向SharePoint搜索所有站点发出查询。 搜索会自动将
的结果修剪为用户有权访问的结果。 以下是有关如何从CSOM调用搜索API的文档。


https://docs.microsoft.com/en-us/sharepoint/dev/general-development/using-the-sharepoint-search-query-apis


I have the following code and trying to populate the dropdownlist with only the list of sites to which the user has access. When the user accesses the page, they see all the site and when the click on the ones to which they do not have access they are prompted with the page to request access to the site. How do I modify the code to only show the list of sites that the user has permission

 protected override void OnPreRender(EventArgs e)
        {
            string permission = string.Empty;
            ddSites.Items.Clear();

            SPSecurity.RunWithElevatedPrivileges(delegate()
                      {

                          using (SPSite siteColl = new SPSite("http://*******/"))
                          {
                              if (siteColl.RootWeb.DoesUserHavePermissions(SPContext.Current.Web.CurrentUser.LoginName, SPBasePermissions.Open))
                              {

                                   {
                                      foreach (SPWeb oWeb in siteColl.RootWeb.GetSubwebsForCurrentUser())
                                      {
                                          ddSites.Items.Insert(0, new ListItem("Please Select a Site", "0"));
                                          foreach (SPWeb web in siteColl.AllWebs)
                                          {
                                              try
                                              {

                                                  ddSites.Items.Add(new ListItem(web.Title, web.ID.ToString()));

                                              }
                                              finally
                                              {
                                                  web.Dispose();
                                              }
                                          }

                                          if (!selectedSiteGuid.Equals(Guid.Empty))
                                          {
                                              ddSites.Items.FindByValue(selectedSiteGuid.ToString()).
                                              Selected = true;

                                            
                                          }
                                      }
                                  }
                              }
                          }
                      });
        }


IPW

解决方案

I haven't done this in a dropdown, but regularly do this using the Search Results web part on a page.  Instead of walking through all the sites try programatically issuing a query to SharePoint Search for All sites.  Search will automatically trim the results to the one the user has access to.  Here's documentation on how to call the search API from CSOM.

https://docs.microsoft.com/en-us/sharepoint/dev/general-development/using-the-sharepoint-search-query-apis


这篇关于仅返回用户有权访问的站点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆