gpt4 book ai didi

c# - Sharepoint 2013 EWS 收件箱 webpart 错误 401 未经授权

转载 作者:行者123 更新时间:2023-11-30 18:32:01 25 4
gpt4 key购买 nike

我正在尝试使用 EWS 访问收件箱邮件。 Kerberos 已配置。但是当我在我的 webpart 中使用 service.UseDefaultCredentials = true 时,我收到 401 错误(未经授权)。解决此问题的解决方案是什么。

   private static bool ValidateCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors) {
return true;
}

protected void Page_Load(object sender, EventArgs e)
{
try
{

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateCertificate);

service.UseDefaultCredentials = true;

service.Url = new Uri(EWSuri.uri);


SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.IsEqualTo(
EmailMessageSchema.IsRead, false), new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, DateTime.Now.AddDays(-14)));

FindItemsResults<Item> findResults = service.FindItems(
WellKnownFolderName.Inbox, sf,
new ItemView(int.MaxValue));

emailblock.InnerHtml = "<div data-itemscount=\"" + findResults.Items.Count + "\"></div>";

foreach (Item item in findResults.Items)
{
EmailMessage mes = (EmailMessage)item;

emailblock.InnerHtml += "<div class=\"emailitem\"><p class=\"emailline clearfix\"><span class=\"emailfield\">From:</span>" +
"<span class=\"emailtext\">" + " " + mes.Sender.Name + "</span></p>" +
"<p class=\"emailline clearfix\"><span class=\"emailfield\">Subject:</span>" +
"<span class=\"emailtext\">" + " " + item.Subject + "</span></p>" +
"<p class=\"emailline clearfix\"><span class=\"emailfield\">Received:</span>" +
"<span class=\"emailtext\">" + " " + item.DateTimeSent + "</span></p></div>";

}
}

catch (Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRemoteException ex)
{
Console.WriteLine("Exception thrown:{0}" ,ex.Message);
}

}

最佳答案

尝试提供另一个具有权限的登录名或凭据。如果您在 AD 环境中,请不要忘记指定域:

exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
exchangeService.Credentials = new NetworkCredential(ExchangeConfig.user,
ExchangeConfig.password,
ExchangeConfig.domain);
exchangeService.AutodiscoverUrl(ExchangeConfig.usermail);

关于c# - Sharepoint 2013 EWS 收件箱 webpart 错误 401 未经授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19091521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com