简体   繁体   中英

MS Exchange Web Service API and 401 unauthorized exception

I am working with Calendar event syncing process, but stuck at one level and need your help, I am authenticating Web Credentials using

By using this i can sync calendar app with my office365 account. But problem occour when configure other Microsoft Exchange account.

How to identify, whether to use username with domain or user name without domain, because office365 except user name with domain (Email Address), where any other Microsoft outlook webapp not require.

By using this problem is resolve, data sync with exchange server, But question is 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)

Which condition/logic is used to identify whether it is office365 or other domain ?

Using the UPN of the user will work both for OnPremise and Office365 so that is the best method to use its just using the down level username won't work in Office365 https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx#down_level_logon_name

(Don't confuse the UPN with the Email Address these are commonly different OnPremise while generally the same in Office365).

You can also use AutoDiscover to detect if a user is using Office365 (however this still need to be authenticated eg

        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");
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM