使用身份验证时,TFS WorkItemStore在ASP.NET MVC应用程序中抛出COMException

Nic*_*zer 7 c# authentication asp.net-mvc tfs-sdk tfs2012

我完全被这个和无休止的google/stackoverflow搜索所困扰.我正在使用2012 Visual Studio SDK连接到TFS 2012并查询工作项存储.下面的代码在控制台应用程序和使用身份验证的ASP.NET MVC应用程序中,或在我的本地计算机上运行的任何场景中都可以正常运行.但是,COMException当我尝试从已部署到服务器并使用(Windows)身份验证的MVC应用程序中实例化WorkItemStore时,我得到了一个.

如果我<authentication mode="Windows" />在web.config中有元素,那没有区别; 只要[Authorize]我的控制器或其任何操作方法上有属性,只要调用下面的最后一行代码,我就会得到一个异常.如果我删除该[Authorize]属性,则不会发生异常.如果我调用代码修饰之前的某个时刻调用下面的代码[Authorize],则不会发生异常.不知何故,使用AuthorizeAttibute会导致此异常.

有关如何解决这个问题的任何想法?或者至少为了更准确地识别真正的根问题?我真的很想了解这里发生了什么.

Uri tfsAddress = new Uri("http://tfs-address:8080/tfs/DefaultCollection");
var myCreds = new NetworkCredential("userName", "password", "domain");
var tfsCreds = new TfsClientCredentials(new WindowsCredential(myCreds), false);

var defaultCollection = new TfsTeamProjectCollection(tfsAddress, tfsCreds);
defaultCollection.EnsureAuthenticated();

var store = defaultCollection.GetService<WorkItemStore>(); // <-- EXCEPTION
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

[COMException(0x80004005):错误HRESULT E_FAIL已从调用COM组件返回.]

Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.DataStoreNative.BeginDataStoreInit(IntPtr handle,String defaultCachePath,String instanceId,Int32 cacheVersion)+0

Microsoft.TeamFoundation.WorkItemTracking.Client.DataStore.Datastore.BeginDataStoreInit(String defaultCachePath,String instanceId,Int32 cacheVersion)+56

Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.InitializeInternal()+ 598

Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.Microsoft.TeamFoundation.Client.ITfsTeamProjectCollectionObject.Initialize(TfsTeamProjectCollection teamProjectCollection)+23

Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.InitializeTeamFoundationObject(String fullName,Object instance)+43

Microsoft.TeamFoundation.Client.TfsConnection.CreateServiceInstance(程序集程序集,String fullName)+91

Microsoft.TeamFoundation.Client.TfsConnection.GetServiceInstance(类型serviceType,Object serviceInstance)+200

Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.GetServiceInstance(类型serviceType,Object serviceInstance)+439

Microsoft.TeamFoundation.Client.TfsConnection.GetService(类型serviceType)+241

Microsoft.TeamFoundation.Client.TfsConnection.GetService()+58

Nic*_*zer 11

解决方案是将应用程序的AppPool的身份更改为域帐户或LocalSystem.

我不能说我完全理解这里幕后发生的事情,但似乎浏览网站的用户的身份验证身份与AppPool身份之间存在某种冲突,而AppPool身份最初是默认身份ApplicationPoolIdentity.如果问题的根本原因是未经授权的访问或类似的东西,在我看来,我应该为匿名用户和经过身份验证的用户获得相同的例外.我还期望一个实际的未授权访问异常,而不是'未定义'的COMException,所以我真的不知道真正的根本原因是什么.如果有人遇到这个问题而需要详细说明,请这样做.


Bra*_*ley 6

对我来说,在某些情况下会出现此错误,例如在本地IIS中使用TFS API创建新站点时.我甚至按照这里的评论无效,我将AppPool标识设置为LocalSystem.我有一个单独的应用程序池.我为TFS API启用了32位应用程序.

对我来说,当我将应用程序池从框架v4.0更改为v2.0然后再返回到v4.0时,问题就停止了.

我不知道为什么它解决了这个问题,但它对我有用.