問題是什麼?如何通過當前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錯誤 –