Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将windows凭据从Web Api传递到SharePoint Api_C#_Asp.net Web Api_Sharepoint - Fatal编程技术网

C# 将windows凭据从Web Api传递到SharePoint Api

C# 将windows凭据从Web Api传递到SharePoint Api,c#,asp.net-web-api,sharepoint,C#,Asp.net Web Api,Sharepoint,我有一个web api,由angular web应用程序通过Windows身份验证调用。我需要使用通过Windows身份验证传递的凭据进入共享点api 下面是我目前拥有的代码示例。(请注意,…表示我省略了一些代码,还有一些用法,我不认为需要在Sharepoint上执行的代码。) 使用Microsoft.SharePoint.Client.Utilities; 使用制度; 使用System.Collections.Generic; 使用System.Threading.Tasks; 使用Syste

我有一个web api,由angular web应用程序通过Windows身份验证调用。我需要使用通过Windows身份验证传递的凭据进入共享点api

下面是我目前拥有的代码示例。(请注意,…表示我省略了一些代码,还有一些用法,我不认为需要在Sharepoint上执行的代码。)

使用Microsoft.SharePoint.Client.Utilities;
使用制度;
使用System.Collections.Generic;
使用System.Threading.Tasks;
使用System.Web.Http;
使用System.Security.Claims;
使用Microsoft.SharePoint.Client;
使用System.Web;
使用SP=Microsoft.SharePoint.Client;
使用System.Security.Principal;
Net系统;
...
公共静态列表GetSPDocumentsById(int itemId)
{  
使用(ClientContext=newclientcontext(“https://...")
{                     
//我相信这是给我的IIS用户身份,而不是Windows
//用户登录API时使用的凭据。
context.Credentials=CredentialCache.DefaultNetworkCredentials;
...
}
}
我的问题与此问题中的问题非常相似:,但解决此问题的步骤无法解决我的问题。如果我检查
HttpContext.Current.User.Identity.Name的值,则在控制器中


我获得了所需的用户名,但如果我选中了
WindowsIdentity.GetCurrent().name;
,我将获得IIS用户帐户。如果
WindowsIdentity.GetCurrent().Name;
调用返回了登录用户的windows帐户,这将解决我的问题。

结果表明,这是本文中解释的Kerbos双跳问题(),为了解决这个问题,我们只需将api移到它试图访问的另一个资源所在的服务器上。

结果表明,这是一个Kerbos双跳问题,如本文所述(),要解决此问题,我们只需将api移到与它试图访问的其他资源相同的服务器上。

如果您使用Web api,则可以使用控制器的用户属性获取当前Windows身份验证用户。然后,您可以获取user.Identity等@Jon我将此api放在控制器的单独服务中,因此我希望避免d尽可能从控制器传递数据。为了澄清,此代码位于web api调用的类库中。然后,您需要将Windows凭据传递到类库中(从web api)。假设您的Web API使用Windows身份验证。我认为作为Web API项目一部分的类库应该可以访问该用户。我认为我的问题是defaultNetworkCredentials返回的不是登录用户。如果您使用的是Web API,您可以通过使用控制器的用户属性。然后,您可以获取User.Identity等@Jon我在控制器的一个单独服务中有此项,因此我希望尽可能避免从控制器传递数据。为了澄清,此代码位于web api调用的类库中。您需要将Windows凭据传递到class库(来自Web API)。假设您的Web API使用Windows身份验证。我认为作为Web API项目一部分的类库应该可以访问该用户。我认为我的问题是defaultNetworkCredentials返回的不是登录用户。