TeamFoundationServerUnauthorizedException
I'm trying to access TeamFoundationServer from another machine, and keep getting TeamFoundationServerUnauthorizedException errors.
I'm writing a simple app to list WorkItems but cannot get access to the Server.
| |
NetworkCredential nc =new NetworkCredential( "myusernameondomain", "mypassword","domain_name_tfs_sits_on" ); TeamFoundationServer tfServer = TeamFoundationServerFactory.GetServer( "http://vsts_server_address:8080", nc ); WorkItemStore wiStore = (WorkItemStore)tfServer.GetService(typeof(WorkItemStore)); WorkItemCollection workItems = wiStore.Query( "SELECT [System.Id], [System.Title] FROM WorkItems); foreach ( WorkItem wi in workItems ) { TreeNode ce = new TreeNode( wi.Type.Name + " " + wi.Id.ToString() + " " + wi.Title, wi.Id.ToString(), "", "http://vsts-dev-single:8080/WorkItemTracking/Workitem.aspx?artifactMoniker=" + wi.Id.ToString(),"_self" ); tvwWorkItems.Nodes.Add(ce); }
|
What's wrong. I've only added the networkcredential because I tried it without, and saw some /username switches when people use command line tf.
[1370 byte] By [
pflangan] at [2007-12-17]
Hi,
Are you seeing the same error when you try without the network credentials? Can you try running a query from the second machine using the Visual Studio UI?
Thanks.
-Mareen.
Yes, the same error regardless of network credentials. and yes to running a query, viewing workitems, creating workitems from within the Visual Studio UI.
I would have thought that I can specify the username / password / domain that I'm using to logon to the TFS in my code.
Hi,
You should be able to pass in the username/password/domain to log in, though we have some known issues in beta3 around using multiple credentials.
Just to clarify - did I get this right : you are able to connect and run queries from the same machine that you are unable to connect to through code?
In the line below, what is being passed in as parameters?
NetworkCredential nc = new NetworkCredential( "myusernameondomain", "mypassword","domain_name_tfs_sits_on" );
The domain parameter should be the domain associated with the credential. E.g: if my user account is domainX\joeuser, the parameters should be
NetworkCredential nc = new NetworkCredential("joeuser", "mypassword", "domainX" );
Thanks.
-Mareen.
Yes, got it right.
and yes, that's exactly what I'm passing via the NetworkCredential.
user VSTS\paul
password mypass
NetworkCredential nc = new NetworkCredential( "paul", "mypass", "VSTS" );
I've also tried any number of combinations of the above, the domain username / password I'm logged into, the computername of the TFS etc.
I spent ages trying to figure it out, found the NetworkCredential class, and thought I had it cracked. Now I'm more cheesed than ever; it should work, but it doesn't.
Is the TFS server in a different domain?
Can you run "tf dir $/ /s:http://yourserver:8080 /login:VSTS\paul,mypass" succesfully from a Visual Studio Command Prompt?
Is there any other code in your app that is creating a TFS object using the TeamFoundationServerFactory? If so, the factory is such that the first connection to the server sets the credentials, so the second call would simply get back the first instance without altering the credentials. The factory was designed for a different purpose, and it doesn't handle this. For RTM, you'll once again be able to directly create a TFS object, and your app can manage credentials as it needs.
Buck
From the command you supplied I got the following response
$/:
$ITIL Test
1 item(s)
Yes, I'm trying to execute the code from a different domain, but I ran the above command from the same computer the code is running from and it works fine.
No, I'm not calling any other code. This is it, in its entirity;
| |
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.WorkItemTracking.Client; using Microsoft.TeamFoundation.WorkItemTracking.Common; using System.Net; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { NetworkCredential nc = new NetworkCredential( "paul.langan-eds", "mypassword","vsts-dev-single" ); TeamFoundationServer tfServer = TeamFoundationServerFactory.GetServer( "http://vsts-dev-single:8080", nc ); WorkItemStore wiStore = (WorkItemStore)tfServer.GetService(typeof(WorkItemStore)); WorkItemCollection workItems = wiStore.Query( "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.WorkItemType] = \"Contact Event\"" ); DataSet ds = new DataSet(); foreach ( WorkItem wi in workItems ) { TreeNode ce = new TreeNode( wi.Type.Name + " " + wi.Id.ToString() + " " + wi.Title, wi.Id.ToString(), "", "http://vsts-dev-single:8080/WorkItemTracking/Workitem.aspx?artifactMoniker=" + wi.Id.ToString(),"_self" ); tvwWorkItems.Nodes.Add(ce); } } } |
The code is listed in Default.aspx.cs
I'm building a hierarchical treeview representation of the work items we're using for workflow tracking.
Does the account under which the web app is running (the app-pool account) has access to the TFServer? This is not needed but I vaguely remember we fixing few bugs on pieces of code running under the service account even though we specify credentials. Can you try adding the service account as contributers or TFSAdmin under the vsts-dev-single team foundation server and let us know if that works?
Thanks.
Another thing I would try is to directly create TeamFoundationServer with the credentials instead of getting it from the factory - to eliminate issues with factory caching. I tried it (with current code though, not beta3 & in same domain) and it worked without errors.