1

我正在尝试解决许多文档存储在不同共享点站点中的问题(不一定在同一服务器上,这意味着它们不是同一站点的子站点)。

我正在考虑创建某种自定义共享点搜索,但我的问题是 - 无权访问特定共享点站点的用户是否可以从该站点获取搜索结果?

这意味着如果他们搜索“文档 X”并且该文档位于他们无权访问的站点上,我希望他们在搜索结果页面上看到该文档位于那里,但仍然不允许他们访问它未经许可(只要看到它存在)。

非常感谢。

4

1 回答 1

0

这是一个关于如何模拟特定用户并将用户看到的搜索结果返回给所有用户的示例。不用说,这当然是一个安全风险,所以谨慎使用:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Data;
using System.Security.Principal;

using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.Search.Query;
using Microsoft.SharePoint.Administration;

namespace SharePointSearchImpersonation.WebPart1
{ 
    [ToolboxItemAttribute(false)]
    public class QuerySearchImpersonatedWebPart : WebPart
    {
        protected override void CreateChildControls()
        {
            try
            {
                // Run elevated since the user, the apppool account, that impersonate other users needs the following 
                // local policies (run secpol.msc): "Impersonate a client after authentication" & "Act as part of the operating system"
                // The apppool account must be granted above rights. 
                SPSecurity.RunWithElevatedPrivileges(
                    delegate
                        {
                            // Setup the windows identity to impersonate the search as. 
                            WindowsIdentity identity = new WindowsIdentity("user3@dev.local");
                            // Create a new ImpersonationContext for the identity
                            using (WindowsImpersonationContext wic = identity.Impersonate())
                            {
                                SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();
                                // Get the search proxy by service application name
                                SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Search Service Application");
                                KeywordQuery query = new KeywordQuery(searchProxy);
                                query.ResultTypes = ResultType.RelevantResults;
                                query.QueryText = "test";
                                query.RowLimit = 25;
                                ResultTableCollection result = query.Execute();
                                DataTable dt = new DataTable();
                                dt.Load(result[ResultType.RelevantResults]);

                                GridView gv = new GridView();
                                Controls.Add(gv);
                                gv.AutoGenerateColumns = true;
                                gv.DataSource = dt;
                                gv.DataBind();

                            }
                        });
            }
            catch (Exception ex)
            {
                Controls.Add(new LiteralControl() {Text = ex.ToString()});
            }
        }
    }
}
于 2013-01-03T22:13:41.000 回答