我们有一个连接到Exchange服务器的MVC应用程序 . 我们曾经使用此代码连接到本地服务器来创建服务:
if (string.IsNullOrEmpty(Current.UserPassword))
{
throw new UnauthorizedAccessException("Exchange access requires Authentication by Password");
}
return new ExchangeService
{
Credentials = new NetworkCredential(Current.User.LoginName, Current.UserPassword),
Url = new Uri(ConfigurationManager.AppSettings["ExchangeServiceUrl"]),
};
这很好,但现在我们的IT部门正在将Exchange服务器迁移到 Cloud ,而一些用户在 Cloud 服务器上,而其他用户在内部 . 所以我把代码更改为:
if (string.IsNullOrEmpty(Current.UserPassword))
{
throw new UnauthorizedAccessException("Exchange access requires Authentication by Password");
}
var user = ConfigurationManager.AppSettings["ExchangeUser"];
var password = ConfigurationManager.AppSettings["ExchangePassword"];
var exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
Credentials = new NetworkCredential(user, password),
};
exchangeService.AutodiscoverUrl(Current.EmaiLuser + "@calamos.com", RedirectionCallback);
exchangeService.Credentials = new NetworkCredential(Current.EmaiLuser + "@calamos.com", Current.UserPassword);
return exchangeService;
我正在使用服务帐户进行自动发现(由于某种原因,它不能与常规帐户一起使用)然后我将服务凭据更改为登录用户,因此他可以访问收件箱 . 问题是,随机,服务器返回“请求失败 . 远程服务器返回错误:(401)未经授权 . ” . 我要求IT部门检查Exchange日志,但是没有任何关于此错误的信息,所以我不知道如何修复它...
1 回答
那么通过 Cloud 你的意思是Office365?
对于 Cloud 中的用户,您需要确保将请求发送到 Cloud 服务器,或者启用跟踪https://msdn.microsoft.com/en-us/library/office/dd633676(v=exchg.80).aspx,然后查看失败请求的路由位置 . 根据您的说法,您的发现将始终指向您的内部服务器,这就是基于 Cloud 的用户请求失败的原因 . 您需要有一种方法来识别 Cloud 中的用户,我建议您只使用单个Office365 endpoints (例如,您不需要自动发现)https // outlook.office365.com / EWS / Exchange的.asmx