我的 ASP.NET Web 应用程序在我们的 Intranet 上使用 Windows 身份验证。我希望它能够向同一域中的另一台服务器发出服务器端 http 请求,该服务器也需要 Windows 身份验证。

在此处提出其他请求时,我已按照有关临时模拟经过身份验证的用户的说明进行操作:

http://msdn.microsoft.com/en-us/library/ff647404.aspx

使用这样的代码:

using System.Security.Principal;

// Obtain the authenticated user's Identity
WindowsIdentity winId = (WindowsIdentity)HttpContext.Current.User.Identity;
WindowsImpersonationContext ctx = null;
try
{
  // Start impersonating
  ctx = winId.Impersonate();
  // Now impersonating
  // Access resources using the identity of the authenticated user
  var request = WebRequest.Create("http://intranet/secureapp");
  request.Credentials = CredentialCache.DefaultCredentials;
  var response = request.GetResponse();
  using (var streamReader = new StreamReader(response.GetResponseStream()))
  {
      Response.Write(streamReader.ReadToEnd());
  }
}
// Prevent exceptions from propagating
catch
{
}
finally
{
  // Revert impersonation
  if (ctx != null)
    ctx.Undo();
}
// Back to running under the default ASP.NET process identity

但是,不幸的是,我总是收到 401 未经授权的错误。

我是否需要使用事件目录配置我们的网络服务器以允许它委派经过身份验证的用户(可以是大约 200 个用户中的任何一个,所以不想做任何事情 200 次 :))?如果是这样,谁能告诉我如何做到这一点?

最佳答案

使用 Windows 配置 Kerberos/委派有几个步骤。

首先,您需要配置 ASP.NET 以使用委派。我假设你在你的 web.config 中配置了这个。

然后,您需要为委派配置 ASP.NET 服务帐户。有时您必须创建一个 SPN。

然后为 IIS 服务器和 Active Directory 中的帐户启用委派。

此处提供了分步说明:http://msdn.microsoft.com/en-us/library/ms998355.aspx
按照步骤 1-3。

关于asp.net - 在 IIS7 windows 2008 中启用双跳委派的步骤,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4334665/

10-13 08:18