C# 如何在web方法中使用提升的权限获取API URL的响应?

C# 如何在web方法中使用提升的权限获取API URL的响应?,c#,asp.net,url,sharepoint-2010,C#,Asp.net,Url,Sharepoint 2010,我们有一个搜索API,其URL格式为webURL+“/\u API/search/query?querytext='“+query+”生成页面上的内容需要其响应。此URL可以通过AJAX直接访问,但该URL只能由管理员用户访问。为了让普通用户使用搜索功能,解决方法是调用web方法,inturn使用提升的权限调用API的URL 我们有如下代码,但我们不确定如何使用提升的权限打开API的URL并返回响应 public string GetSearchListItems(string query) {

我们有一个搜索API,其URL格式为
webURL+“/\u API/search/query?querytext='“+query+”生成页面上的内容需要其响应。此URL可以通过AJAX直接访问,但该URL只能由管理员用户访问。为了让普通用户使用搜索功能,解决方法是调用web方法,inturn使用提升的权限调用API的URL

我们有如下代码,但我们不确定如何使用提升的权限打开API的URL并返回响应

public string GetSearchListItems(string query)
{
    var superUser = SPContext.Current.Web.AllUsers[@"SHAREPOINT\SYSTEM"];
    var superToken = superUser.UserToken;
    var webURL = SPContext.Current.Web.Url;
    using (var site = new SPSite(webURL, superToken))
    {
        string searchURL = webURL + "/_api/search/query?querytext='" + query + "'" +"&rowlimit=4&sortlist='ViewsLifeTime:descending'";

        using (var elevatedWeb = site.OpenWeb())
        {
            // code to open searchURL using elevated privileges and return the response of searchURL
        }
    }
}
我们尝试了以下方法来代替上述评论:

WebClient client = new WebClient();
string response = client.DownloadString(searchURL);
return response;
。。。但这会导致401(未经审核)例外


如何将提升的权限(SharePoint\System帐户)集成到打开搜索API的URL中?

您是否尝试过将在RunWithElevatedPrivileges()委托中注释的代码包装起来

e、 g


试过这个,;仍然是401。
SPSecurity.RunWithElevatedPrivileges(delegate()
{
WebClient client = new WebClient();
string response = client.DownloadString(searchURL);
return response;
});