0

我试图在模拟特定用户时执行搜索查询。

目标是拥有一个接收用户登录名(通过查询字符串或请求标头)的 Web 服务,执行全文查询并返回结果,同时遵守安全调整。

换句话说,我只需要获得模拟用户有权看到的结果。

我目前的代码是:

            var spUser = SPContext.Current.Web.EnsureUser(loginName);

            HttpRequest request = new HttpRequest("", SPContext.Current.Web.Url, "");

            var web = SPContext.Current.Web;

            HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter(CultureInfo.CurrentCulture)));
            if (HttpContext.Current.Items.Contains("HttpHandlerSPWeb"))
            {
                HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
            }
            else
            {
                HttpContext.Current.Items.Add("HttpHandlerSPWeb", web);
            }

            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            typeof(WindowsIdentity).GetField("m_name", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(identity, spUser.LoginName);

            HttpContext.Current.User = new GenericPrincipal(identity, new string[0]);
            identity.Impersonate();

            //execute query here

基本上,我在实例化 FullTextQuery 之前替换了当前身份,但这与什么都不做一样,因为结果只会根据真实登录的用户而变化,而不是被模拟的用户。

这里有什么提示吗?

在此先感谢,干杯!

4

1 回答 1

0

在以提升的权限运行时,我能够通过模拟来使其工作。在这里查看我的帖子:http: //vishalseth.com/post/2013/11/05/Impersonated-Searching-against-SharePoint.aspx

于 2014-02-19T05:32:00.333 回答