[英]How connect to Exchange Server via current Windows user credentials?
What the problem is? 问题是什么?
We have an Exchange Server 2010 SP2, IIS 7.5 and a console app in VS2013. 我们在VS2013中有一个Exchange Server 2010 SP2,IIS 7.5和一个控制台应用程序。
So we have done the following: 所以我们做了以下事情:
TimeZoneInfo timeZone = TimeZoneInfo.Local;
ExchangeService EWSservice = new ExchangeService(ExchangeVersion.Exchange2010_SP2, timeZone);
//EWSservice.Url = new Uri("our url");
EWSservice.AutodiscoverUrl("my@mail.com", RedirectionUrlValidationCallback);
Both ways to define the url are working. 定义网址的两种方式都有效。 Trying to set credentials:
尝试设置凭据:
EWSservice.Credentials = new WebCredentials("my@mail.com", "mypass");
This works too. 这也有效。 But I want to connect by using the current Windows user credentials.
但我想通过使用当前的Windows用户凭据进行连接。 Some code samples that had been used and crashed:
一些已使用和崩溃的代码示例:
EWSservice.Credentials = new WebCredentials(CredentialCache.DefaultCredentials);
EWSservice.UseDefaultCredentials = true;
EWSservice.Credentials = (NetworkCredential)CredentialCache.DefaultCredentials;
All of this has returned a 401 error: Unauthorized 所有这些都返回了401错误:未经授权
Additionally, I have edited the app.config like this - but it doesn't work: 另外,我已经像这样编辑了app.config - 但它不起作用:
<authentication mode="Windows">
</authentication>
<identity impersonate="false"/>
<!--Other stuff-->
</authentication>
Then, I have read about authentication modes and found this: Windows User getting "access denied" from exchange server 然后,我已阅读有关身份验证模式的信息并发现: Windows用户从Exchange服务器获取“访问被拒绝”
The admin has set this delegate option, but the connection is still not working... 管理员已设置此委托选项,但连接仍然无法正常工作...
Now I have added this: 现在我添加了这个:
EWSservice.TraceEnabled = true;
and I get an Exchange response in the console: 我在控制台中收到Exchange响应:
HTTP/1.1 401 Unauthorized
Content-Length: 0
Date: Wed, 20 Apr 2016 07:59:01 GMT
Set-Cookie: exchangecookie=bfab7cdda62a4bf8be5b43689199fcf6; expires=Thu, 20-Apr
-2017 07:59:02 GMT; path=/; HttpOnly
Server: Microsoft-IIS/7.5
WWW-Authenticate: Basic realm="our-domain"
X-Powered-By: ASP.NET
Any ideas? 有任何想法吗?
I don't think your approach is possible but you may want to look at this .... 我不认为你的方法是可行的,但你可能想看看这个....
How to get the current user's Active Directory details in C# 如何在C#中获取当前用户的Active Directory详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.