-->

AD用户认证(AD User Authentication)

2019-09-24 00:33发布

I am attempting to create an ASP.NET (.NET 3.5) website to connect to our Exchange 2010 server through Exchange Web Services, I am able to connect to EWS when I define the username, password and domain to authenticate with but I would like, if possible, to not include login details in my code.

In IIS I have enabled Integrated Windows Authentication for the site, in web.config of the site I have <authentication mode="Windows"/>.

The following code is what I have been woking with:

svc.UseDefaultCredentials = True
svc.Credentials = New WebCredentials()
svc.Url = New Uri(svcURL)

With the above code I am receiving the message:

When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

When I attempt to use svc.Credentials = CredentialCache.DefaultNetworkCredentials (in place of svc.Credentials = New WebCredentials()) I receive the error message:

Unable to cast object of type 'System.Net.SystemNetworkCredential' to type 'Microsoft.Exchange.WebServices.Data.ExchangeCredentials'.

As mentioned, the only thing that has worked is to define the user credentials to authenticate to by hardcoding user login details, which I would rather not do: svc.Credentials = New WebCredentials("username","password","domain")

Has anyone been able to authenticate to EWS using the credentials of the current logged in user in an ASP.NET website?

Answer 1:

默认情况下,这是不可能从一个服务器到另一个(Exchange服务器)(在其上托管你的ASP.NET网站的服务器)委托用户的凭证。 这被称为“服务器跳”和Windows将阻止它在默认情况下作为一种安全措施。

你有几个选项来解决此问题:

  1. 使用Kerberos:当启用Kerberos它使得可以委派服务器之间的用户凭据使用Windows身份验证时。 我不知道如何设置Kerberos,因为我只是一个不起眼的开发人员,但也许你的系统管理员可以帮助您的具体细节。 据我所知,你需要设置你的ASP.NET服务器,以允许用户授权。
  2. 设置IIS应用程序池的用户身份:如果Kerberos是不是一种选择,你可能会改变你的ASP.NET网站下运行的应用程序池的标识。 首先定义在IIS管理器中的新应用程序池。 然后转到该应用程序池高级设置对话框,并设置身份被允许访问您的Exchange服务器的域用户。 :在应用程序池标识更多资讯http://technet.microsoft.com/en-us/library/cc771170(v=WS.10).aspx 。
  3. 设置<identity>元素:如果您由于某种原因无法更改应用程序池,您可以使用<identity>元素在你的web.config文件试试你的ASP.NET网站的模拟。 ASP.NET让你在注册表中存储的凭据,这样你就不必把他们直接在你的web.config文件的选项。 更多资讯: http://msdn.microsoft.com/en-us/library/72wdk8cc(v=vs.90).aspx
  4. 使用<的appSettings> ellement和加密:我能想到的最后一个选项是简单地把凭据你的web.config文件中正常<的appSettings>,然后加密整个<appSettings>部分。 那么只需在阅读使用你的代码中的appSettings 的AppSettingsReader类 。 .NET允许你在web.config文件的部分加密开箱,你可以不用事件注意到,部分是加密的读取设置。 .NET需要解密你的照顾。 更多资讯: http://msdn.microsoft.com/en-us/library/zhhddkxy.aspx


文章来源: AD User Authentication