使用Web API核心获取EWS文件夹
在尝试绑定Web API Core中的EWS文件夹时,在IIS中获得401(未经授权)错误(本地工作正常)。下面的最小代码。
ExchangeService service = new ExchangeService();
service.Url = new Uri(ewsUrl)
service.UseDefaultCredentials = true;
service.Credentials = CredentialCache.DefaultNetworkCredentials;
Folder rootFolder = await Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
IIS设置:
- 匿名= false
- 模仿= false(true给出错误500)
- Windows authentication = true
- 其他设置= false
.net Core似乎不支持代码模拟,因此我在.NET框架中尝试了上述代码,并包含它在此陈述中。不幸的是,相同的401错误。
IIdentity WinId = HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
WindowsImpersonationContext wic = wi.Impersonate();
try
{
...
}
catch (Exception ex1)
{ }
finally
{
wic.Undo();
}
感谢您的帮助!
Getting 401 (Unauthorized) error in IIS while trying to bind to the EWS folder in Web Api Core (locally works fine). The minimal code below.
ExchangeService service = new ExchangeService();
service.Url = new Uri(ewsUrl)
service.UseDefaultCredentials = true;
service.Credentials = CredentialCache.DefaultNetworkCredentials;
Folder rootFolder = await Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
IIS settings:
- Anonymous = false
- Impersonation = false (true gives the error 500)
- Windows Authentication = true
- Other settings = false
.Net Core seems to be does not support in-code impersonation, so I tried above code in .NET Framework, inclosed it in this statement. Unfortunately, the same 401 error.
IIdentity WinId = HttpContext.Current.User.Identity;
WindowsIdentity wi = (WindowsIdentity)WinId;
WindowsImpersonationContext wic = wi.Impersonate();
try
{
...
}
catch (Exception ex1)
{ }
finally
{
wic.Undo();
}
Appreciate for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论