我有一个SharePoint 2019服务器场,它具有2种身份验证方法:NTLM和表单。 如果我使用以下代码通过NTLM连接:
using (ClientContext context = new ClientContext("https://myserver"))
{
context.ExecutingWebRequest += (object sender, WebRequestEventArgs e) =>
{
e.WebRequest.Headers.Remove("X-FORMS_BASED_AUTH_ACCEPTED");
e.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
};
context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
CredentialCache cache = new CredentialCache();
NetworkCredential cred = new NetworkCredential("windows username", "windows pwd", "domain");
cache.Add(new Uri(https://myserver), "NTLM", cred);
context.Credentials = cache;
var web = context.Web;
context.Load(web.Lists);
await context.ExecuteQueryAsync();
return true;
}
工作正常。 如果我尝试使用此方法,请使用表单身份验证:
using (ClientContext context = new ClientContext("https://myserver"))
{
context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
context.Credentials = new NetworkCredential("username", "password");
var web = context.Web;
context.Load(web.Lists);
await context.ExecuteQueryAsync();
return true;
}
我不断收到403,禁止。我应设置为触发Form Authentication而不是Windows的HTTP标头是什么?