[英]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.