我在IIS中有一个网站,其身份验证模式设置为Windows
我需要使用restsharp:
var client = new RestClient(item.Url);
var request = new RestRequest("/account/Menu", Method.GET);
request.AddParameter("SSO_Token", token);
client.PreAuthenticate = false;
client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator(new NetworkCredential(username, password, domain));
// I also tried following codes with no luck:
// client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator();
// client.Authenticator = new RestSharp.Authenticators.NtlmAuthenticator(username, password);
var response = client.Execute(request);
现在问题是我收到了这个错误:
HTTP Error 401.1 - Unauthorized
You do not have permission to view this directory or page using the credentials that you supplied.
我确定提供的凭据是正确的。
答案 0 :(得分:0)
这为我修好了:https://www.codeproject.com/Questions/4043926/Why-is-my-API-throws-an-error-when-using-authentic
request.UseDefaultCredentials = true;