使用ASP.NET和TFS api进行Passthrough(模拟)身份验证

Chr*_*s S 6 asp.net impersonation tfs tfs-sdk

我正在尝试在使用TFS2010 API的ASP.NET网站中启用passthrough或模拟身份验证.

我已经使用Cassini正常工作,但是在IIS 7.5(Windows 7)中出现了问题.

我发现了关于这个主题的博客文章,并尝试了以下内容:

private static void Test()
{
    TfsTeamProjectCollection baseUserTpcConnection = 
            new TfsTeamProjectCollection(new Uri(Settings.TfsServer));

    // Fails as 'baseUserTpcConnection' isn't authenticated
    IIdentityManagementService ims = 
            baseUserTpcConnection.GetService<IIdentityManagementService>();

    // Read out the identity of the user we want to impersonate
    TeamFoundationIdentity identity = ims.ReadIdentity(
            IdentitySearchFactor.AccountName, 
            HttpContext.Current.User.Identity.Name,
            MembershipQuery.None, 
            ReadIdentityOptions.None);

    TfsTeamProjectCollection impersonatedTpcConnection = new 
            TfsTeamProjectCollection(new Uri(Settings.TfsServer), 
            identity.Descriptor);
}
Run Code Online (Sandbox Code Playgroud)

当我使用卡西尼时,除此之外不需要任何东西

collection = new TfsTeamProjectCollection(new Uri(server));

我已启用web.config设置(并安装了Windows Auth模块):

<authentication mode="Windows"/>
<identity impersonate="true" />
Run Code Online (Sandbox Code Playgroud)

有什么明显的东西我错过了吗?

Chr*_*s S 7

解决方案1

这是委托方法.正如Paul所指出的,它是您的活动目录中的一个设置:

  1. 在"Active Directory用户和计算机"控制台的计算机节点中查找IIS服务器.
  2. 单击委托选项卡,然后选择第二个选项: 广告

  3. 在IIS根文件夹中创建"缓存"目录

  4. 将以下内容添加到web.config:

<appSettings>
<add key="WorkItemTrackingCacheRoot" value="C:\path-to-web-root\Cache\"/>
</appSettings>

  1. 确保您的web.config包含:

<system.web>
<identity impersonate="true" />
</system.web>

  1. 打开Windows身份验证和impersatonation并禁用IIS身份验证中的所有其他内容:

IIS

解决方案2

避免上述步骤的另一个解决方案是在TFS:8080站点下运行您的应用程序,作为新的应用程序.然后,当您在与应用程序调用的Web服务相同的上下文中运行时,将删除跃点问题.

  • 创建一个新的应用程序池,使用网络标识.
  • 确保您的应用程序已关闭匿名身份验证
  • 确保已启用Windows身份验证.
  • 添加<identity impersonate="true" />到Web配置.


Pau*_*ney 5

我想知道你是否在这里遇到旧的双跳问题?

  • 从内存开始(这是几年前) - 我认为它只是针对AD中的服务器设置(Trust for Delegation?) - 假设您的网络已经在运行Kerberos - 如果没有,为什么不呢; o) (2认同)