首页 文章

MS Exchange Web服务API和401未经授权的例外

提问于
浏览
2

我正在使用Calendar事件同步过程,但是在一个级别并且需要您的帮助,我正在使用Web身份验证进行身份验证

exchangeService.Credentials = new WebCredentials("user@domain", "pwd");

通过使用此我可以与我的office365帐户同步日历应用程序 . 但配置其他Microsoft Exchange帐户时出现问题 .

如何识别,是否使用域名或用户名而不使用域名,因为office365除了用户名域名(电子邮件地址),其他任何Microsoft Outlook webapp都不需要 .

exchangeService.Credentials = new WebCredentials("user", "pwd", "domain");

通过使用此问题解决,数据与交换服务器同步,但问题是 How can we handle/check whether to use user name with domain(for outlook.office365 Login) or user name without domain(for Microsoft outlook webapp login)

使用哪种条件/逻辑来确定它是office365还是其他域?

1 回答

  • 0

    使用用户的UPN将同时适用于OnPremise和Office365,因此使用其仅使用低级用户名的最佳方法将无法在Office365中使用https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx#down_level_logon_name

    (不要将UPN与电子邮件地址混淆,这些通常是不同的OnPremise,而在Office365中通常是相同的) .

    您还可以使用自动发现来检测用户是否正在使用Office365(但是,这仍然需要进行身份验证,例如

    AutodiscoverService adAutoDiscoverService = new AutodiscoverService(ExchangeVersion.Exchange2013_SP1);
            adAutoDiscoverService.Credentials = new NetworkCredential("UserName", "Password");
            adAutoDiscoverService.EnableScpLookup = false;
            adAutoDiscoverService.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
            adAutoDiscoverService.PreAuthenticate = true;
            adAutoDiscoverService.TraceEnabled = true;
            adAutoDiscoverService.KeepAlive = false;            
            GetUserSettingsResponse gsp = adAutoDiscoverService.GetUserSettings("username@domain.com", UserSettingName.UserMSOnline);
            Object UserMSOnline = null;
            if (gsp.Settings.TryGetValue(UserSettingName.UserMSOnline, out UserMSOnline))
            {
                if ((String)UserMSOnline == "True")
                {
                    Console.WriteLine("Office365");
                }
            }
    

相关问题