c# - 使用 EWS 托管 API 验证登录凭据

标签 c# exchangewebservices office365api

有没有一种方法可以在不发送电子邮件的情况下验证用户使用 EWS 托管 API 提供的登录凭据。我在 [ExchangeService] 对象上使用 AutodiscoverUrl 方法,但花费的时间太长?任何建议将不胜感激。

        try
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            service.Credentials = new WebCredentials("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f38b8b8b8bb38a8a8add909c9e" rel="noreferrer noopener nofollow">[email protected]</a>", "password");
            service.AutodiscoverUrl("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed95959595ad949494c38e8280" rel="noreferrer noopener nofollow">[email protected]</a>", RedirectionUrlValidationCallback);    

            Console.WriteLine("Credentials validated successfully");
            Console.ReadLine();

        }

        catch(Exception e)
        {
            Console.WriteLine(e.Message);
            Console.ReadLine();
        }

最佳答案

一种加快速度的方法,虽然不太好,但很有效,就是自己设置服务 URL。 首先通过在 Debug模式下运行 autodiscoverurl 方法来获取交换服务 url:

enter image description here

然后,不要在服务上运行 autodiscoverurl 方法,而是添加从 autodiscoverurl 方法获取的 url:

 service.Url = new Uri("https://yourExchangeURL.com/EWS/Exchange.asmx");

您可以对邮件帐户 ( Check exchange credentials remotely and check user logged in ) 发出请求,而不是调用自动发现来验证用户凭据

var findFolderResults = service.FindFolders(WellKnownFolderName.Root, new SearchFilter.IsGreaterThan(FolderSchema.TotalCount, 0), new FolderView(10));

您的最终代码将如下所示

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdc5c5c5c5fdc4c4c493ded2d0" rel="noreferrer noopener nofollow">[email protected]</a>", "password");
service.Url = new Uri("https://yourExchangeURL.com/EWS/Exchange.asmx");
var findFolderResults = service.FindFolders(WellKnownFolderName.Root, new SearchFilter.IsGreaterThan(FolderSchema.TotalCount, 0), new FolderView(10));

关于c# - 使用 EWS 托管 API 验证登录凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36587942/

相关文章:

c# - 如何在 IronPython 中调用 C#/.NET 命名空间?

ios - 为什么我不能使 HttpWebRequest 与 NTLM 身份验证一起使用

microsoft-graph-api - 尝试使用 ms-graph API 创建工作簿时,已创建损坏的工作簿

soap - 使用 postman 测试 Microsoft EWS(Exchange Web 服务)

c# - 无法从 Exchange Web 服务检索资源(房间)

javascript - 此 api 版本不支持 onedrive 文件选择器 aadsts70001 应用程序

php - Outlook 通知 REST API 订阅所有日历

c# - 从 Resharper 的检查结果窗口中删除 "Hints"

c# - VS 2012 TFS 卡在加载身份提供程序上

c# - 无法使用 C# 解密使用 PHP 加密的数据 (Rijdael-128)