I’ve decide to develop applications for Team Foundation Server. To do so, I’ve install a virtual machine with TFS running on Windows Server 2003 R2. Since TFS installed on a virtual machine, I did not set a Domain Controller. Then I’ve start to code my applicaiton on my “real” machine running Windows Xp Sp2. But I’ve failed to login TFS as shown below:
Well, I’ve diffrent users on difrent machines; but API should at least allow me to enter username and password, right!? I’ve create user on virtual machine with the same name and password on my real machine…
Finally I’ve found the following lines of code that solves my problem
tfs = TeamFoundationServerFactory.GetServer("Server Name", new UICredentialsProvider()); tfs.EnsureAuthenticated();
EnsureAuthenticated function placed on 2nd line checks whether you’ve successfully loged into TFS, if not, simply throws TeamFoundationServerUnauthorizedException exception to halt your application. Since I’ve users with the same username and password no login dialog displayed, but in documentation its told so…
Instead of EnsureAuthenticated function, you can also use Authenticate. These are the only functions that will display the login dialog.
Then what is the diffrence between these two functions? Answer is the performance : Authenticate function will connect to the server on every call, while EnsureAuthenticated function will connect to the server if no user is not authenticated.