简体   繁体   English

休息呼叫WebException 401仅在混合身份验证Webapp中未经授权

[英]Rest call WebException 401 Unauthorized only in mixed authentication webapp

I've come across a strange behaviour when trying to make a rest call from outside an SharePoint app (specificly from a .NET console application). 尝试从SharePoint应用程序外部(特别是来自.NET控制台应用程序)进行调用时,遇到了一个奇怪的行为。 As long as I use DefaultCredentials everything is fine, as long as my webapplication does not allow FBA (form based authentication) I'm able to hand over NetworkCredentials without problems. 只要我使用DefaultCredentials,一切都很好,只要我的Web应用程序不允许FBA(基于表单的身份验证),我就可以毫无问题地移交NetworkCredentials。

But as soon as FBA authentication is activated I'm not able to make the rest call and 401 Unauthorized is returned. 但是,一旦激活了FBA身份验证,我将无法拨打其余电话,并返回401未经授权。

var req = (HttpWebRequest)HttpWebRequest.Create("http://{url}/_api/web/title");
req.Method = "GET";
req.Credentials = new NetworkCredential("{user}", "{pass}");
req.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
var response = (HttpWebResponse)req.GetResponse();

I also tried this way to hand over credentials like this: 我也尝试过这种方式来交出这样的凭证:

var req = (HttpWebRequest)HttpWebRequest.Create("http://{url}/_api/web/title");
req.Method = "GET";
req.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
var ccache = new CredentialCache();
ccache.Add(new Uri("http://{url}"), "Basic", new NetworkCredential("{user}", "{pass}"));
req.Credentials = ccache;
var response = (HttpWebResponse)req.GetResponse();

Does anyone have a hint or idea what could be wrong and how I can achieve my goal to access rest api with credentials in a mixed authentication web app? 是否有人暗示或想法可能出什么问题,以及我如何实现在混合身份验证Web应用程序中使用凭据访问rest api的目标?

A workaround that should work would be to extend your SharePoint web application to a second zone - and on that zone don't have FBA turned on. 一种可行的解决方法是将SharePoint Web应用程序扩展到第二个区域-并且在该区域上未打开FBA。 So you'd have something like this: www.mysharepointsite.com <- FBA + Windows Authentication access restapi.mysharepointsite.com <- Windows Authentication Only 因此,您将具有以下内容:www.mysharepointsite.com <-FBA + Windows身份验证访问restapi.mysharepointsite.com <-仅Windows身份验证

And then just point your calls to restapi.mysharepointsite.com instead of www.mysharepointsite.com. 然后,只需将您的呼叫指向restapi.mysharepointsite.com即可,而不是www.mysharepointsite.com。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Veracode Rest API 只返回 401 未授权 - Veracode Rest API is only returning 401 unauthorized Web 异常:远程服务器返回错误 (401) 未授权 - Webexception:remote server returned an error (401)unauthorized REST调用异常:设置内部异常时,出现401 UNAUTHORIZED循环 - REST call exception: 401 UNAUTHORIZED loop when inner exception is set 从通用应用程序在Twitter上发布状态时显示401未经授权(WebException) - 401 Unauthorized (WebException) while posting status on Twitter from Universal app 使用 HttpClient.GetAsync() 使用具有基本身份验证的 WCF REST 服务导致 (401) 未经授权 - Consuming a WCF REST service with Basic authentication using HttpClient.GetAsync() results in (401) Unauthorized 401仅在服务器上时未经授权 - 401 Unauthorized only when on server 使用基本身份验证调用web api始终从IIS中获取401未授权 - Call web api with basic authentication always get 401 unauthorized from IIS SharePoint 仅应用程序身份验证抛出“远程服务器返回错误:(401)未经授权。” - SharePoint App-Only Authentication throwing “The remote server returned an error: (401) Unauthorized.” Aurelia Windows身份验证 - 发布401未经授权 - Aurelia Windows Authentication - Post 401 Unauthorized Trello Rest API 创建卡返回 401 Unauthorized - 但只能通过代码 - Trello Rest API Create Card returns 401 Unauthorized - but only via Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM