【问题标题】:EWS from WebSite using user credentials and windows authentication for intranet来自 WebSite 的 EWS 使用 Intranet 的用户凭据和 Windows 身份验证
【发布时间】:2014-08-31 17:18:00
【问题描述】:

我正在尝试了解如何配置需要传递用户凭据并获取一些邮件内容的网站 (ASP.Net)

根据应用程序池配置,我会遇到不同类型的错误, 完整的方法是什么?我的意思是代码+配置;o)

我不想写用户和密码,而是通过windows认证来获取它们

谢谢

代码:

Service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
            {
                Url =
                    new Uri(
                    "https://xxx/yyy.asmx"),
                //UseDefaultCredentials = true doesnt help
            };
        var view = new ItemView(1820);

        // Find the first email message in the Inbox that has attachments. This results
        FindItemsResults<Item> results = Service.FindItems(folderName, view); 
        //Here I get the error 401

【问题讨论】:

    标签: email authentication exchangewebservices intranet integrated


    【解决方案1】:

    看看Get started with EWS Managed API client applications,它涵盖了让您振作起来的基础知识。请注意,当您使用 UseDefaultCredentials 时,您必须在加入域的计算机上,并且用户已登录,并且您必须以本地服务器为目标。我们测试了该场景,以下代码在该场景中有效。

    using System;
    using Microsoft.Exchange.WebServices.Data;
    
    namespace HelloWorld
    {
        class Program
        {
            static void Main()
            {
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
                service.UseDefaultCredentials = true;
                service.TraceEnabled = true;
                service.TraceFlags = TraceFlags.All;
                //Replace the URL below with your own, but using AutoDiscover is recommended instead
                service.Url = new Uri("https://computer.domain.contoso.com/EWS/Exchange.asmx");
    
                FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox,
                                                                   new ItemView(1));
            }
        }
    }
    

    如果这对您不起作用,那么您可能想尝试使用模拟。请参阅this thread,我认为他们的情况类似。有关模拟的更多信息,请参见 MSDN:Impersonation and EWS in Exchange

    【讨论】:

    • 感谢您的回答,但仍不清楚,我的情况很简单,可能是双环问题。 IIS 应用程序从经过身份验证的 Windows 集成 AD 用户获取请求,因此它可以识别用户凭据。我仍然不知道如何将它们隐式传递给 EWS... 客户端已登录,但 FindItemsResults 失败并出现 401 和类似错误
    • 感谢您提及 UseDefaultCredentials 仅适用于本地 Exchange Server。 (我不记得在微软的文档中提到过)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-17
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    相关资源
    最近更新 更多