September 26, 2006 3:47 AM
by Ed Kisinger
Say you built an application that connects to TFS and you want a dialog box to appear if a user is not authorized to connect to TFS. To do this is quite simple. There are two methods you might have seen when you are playing with the TeamFoundationServer object, Authenticate() and EnsureAuthenticated(). The difference between the two is Authenticate will always call the server and EnsureAuthenticated will only be called if the user has not already authenticated to the server. You should use the EnsureAuthenticated method as a performance point since you only want the call to go to the server if the user has not authenticated. Notice we are using the TeamFoundationServer constructor instead of the Factory; you can use the factory if you wish. The deciding point that you need to decide is if you want to reference the same object on subsequence calls and without the need to re-authenticate. Remember the factory method will return a cache instance of the object.
TeamFoundationServer tfs = new TeamFoundationServer(TFSServerName,new UICredentialsProvider());
If the user presses cancel on the dialog box then a UnauthorizedException will be thrown ,so handle it gracefully.
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
Ed Blankenship is a Product Manager at Microsoft for Visual Studio Online. I am an author of a few books, former Microsoft MVP of the Year, and former ALM consultant.
Managed Windows Shared Hosting by OrcsWeb
Site design by Jeremy Kratz