问题是什么?如何通过当前Windows用户凭据连接到Exchange Server?
我们在VS2013中安装了Exchange Server 2010 SP2,IIS 7.5和控制台应用程序。
所以我们做了以下内容:
TimeZoneInfo timeZone = TimeZoneInfo.Local;
ExchangeService EWSservice = new ExchangeService(ExchangeVersion.Exchange2010_SP2, timeZone);
//EWSservice.Url = new Uri("our url");
EWSservice.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
两种方式来定义的URL都在工作。 试图设置凭据:
EWSservice.Credentials = new WebCredentials("[email protected]", "mypass");
这也适用。但我想通过使用当前的Windows用户凭据进行连接。已经使用和崩溃的一些代码示例:
EWSservice.Credentials = new WebCredentials(CredentialCache.DefaultCredentials);
EWSservice.UseDefaultCredentials = true;
EWSservice.Credentials = (NetworkCredential)CredentialCache.DefaultCredentials;
所有这一切都返回401错误:未经授权
此外,我已编辑的app.config这样的 - 但它不工作:
<authentication mode="Windows">
</authentication>
<identity impersonate="false"/>
<!--Other stuff-->
</authentication>
然后,我看了一下认证方式,发现这一点: Windows User getting "access denied" from exchange server
管理有设置这个选项代表,但连接仍然没有工作...
现在我已经加入此:
EWSservice.TraceEnabled = true;
和我在控制台的交换响应:
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
任何想法?
所以是应用失败或你想做到这一点在ASP控制台。净?你可能想看看fiddler中的一些请求,并看看它试图使用的Authentication头(例如Basic或NTLM)。这是旧的,但考虑到EWS托管API仍然使用Httpwebrequest仍然相对https://blogs.msdn.microsoft.com/buckh/2004/07/28/authentication-in-web-services-with-httpwebrequest/ –
它的发生在控制台App中。使用HttpWebRequest也会返回401错误 –