我正在尝试构建一个在TFS中添加工作项的ASP.NET页面。
我已经启用了模拟和Windows身份验证:
<authentication mode="Windows" />
<identity impersonate="true" password="" userName="" />
<customErrors mode="Off" />
在页面上,我访问TFS并尝试添加工作项:
TfsTeamProjectCollection prjCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("xxx"));
WorkItemStore store = prjCollection.GetService<WorkItemStore>();
...
然而,只有我在ASP.NET模拟中选择了“特定用户”并存储了凭据时,它才能正常工作。当选择“已验证的用户”时,它无法工作。我已经检查过SpecificUser和Authenticated User是相同的,但在后一种情况下我会收到权限错误(这表明模拟未正确工作)。
TF30063: You are not authorized to access XXX. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.TeamFoundation.Client.TeamFoundationClientProxyBase.AsyncWebRequest.ExecRequest(Object obj)
--- End of inner exception stack trace ---
at Microsoft.TeamFoundation.Client.TeamFoundationClientProxyBase.ProcessHttpResponse(HttpWebResponse response, Stream responseStream, WebException webException, XmlReader& xmlResponseReader)
at Microsoft.TeamFoundation.Client.TeamFoundationClientProxyBase.ExecWebServiceRequest(HttpWebRequest request, XmlWriter requestXml, String methodName, HttpWebResponse& response)
at Microsoft.TeamFoundation.Framework.Client.LocationWebService.Connect(Int32 connectOptions, ServiceTypeFilter[] serviceTypeFilters, Int32 lastChangeId)
at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.Connect(ConnectOptions connectOptions)
at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.EnsureConnected(ConnectOptions optionsNeeded)
at Microsoft.TeamFoundation.Framework.Client.FrameworkServerDataProvider.get_InstanceId()
at Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore.InitializeInternal()
at Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.InitializeTeamFoundationObject(String fullName, Object instance)
at Microsoft.TeamFoundation.Client.TfsConnection.CreateServiceInstance(Assembly assembly, String fullName)
at Microsoft.TeamFoundation.Client.TfsConnection.GetService(Type serviceType)
at Microsoft.TeamFoundation.Client.TfsConnection.GetService[T]()
at ASP.index_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
以下变量在两种情况下看起来都是相同的:
HttpContext.Current.Request.LogonUserIdentity.Name
HttpContext.Current.Request.IsAuthenticated
HttpContext.Current.User.Identity.Name
System.Environment.UserName
System.Security.Principal.WindowsIdentity.GetCurrent().Name
有什么想法吗?
编辑:
正如约翰在下面提到的那样,问题是由于 Kerberos委派引起的。
我发现以下文章和附带工具非常有用,可以解释和缓解此问题:
DelegConfig - 一个帮助解决Kerberos身份验证和委派问题的工具