我已经花了几个小时试图解决这个问题,我希望有人能提供帮助。用户使用 Azure AD(Microsoft 组织帐户)向我们的 ASP.NET 站点进行身份验证。理想情况下,我希望能够与 Exchange Web 服务连接,但我无法弄清楚如何传递凭据。通过搜索,我发现无法从 User.Identity 获取密码。
我在使用 Pop 或 IMAP 时遇到了同样的问题。
此代码返回“无法定位自动发现服务”如果我明确告诉它服务器名称,我会收到 401 未经授权的错误
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl(User.Identity.Name, RedirectionUrlValidationCallback);
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}