2014-03-25 33 views
1

我擁有本地tfs 2012.在Visual Studio 2012上,使用c#,我編寫了通過編程連接到tfs服務器的程序。但我有錯誤:以編程方式授權給tfs的錯誤

{"TF30063: You are not authorized to access http://server:8080/tfs ."} System.Exception {Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException}

我的代碼:

Uri collectionUri = new Uri("http://server:8080/tfs"); 
NetworkCredential netCred = new NetworkCredential("login","password"); 
BasicAuthCredential basicCred = new BasicAuthCredential(netCred); 
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred); 
tfsCred.AllowInteractive = false; 
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred); 
teamProjectCollection.EnsureAuthenticated();//throw error here 

你能幫我解決這個錯誤?

P.S.我嘗試做連接這種方式,但我有同樣的錯誤:

var projectCollection = new TfsTeamProjectCollection(
new Uri("http://myserver:8080/tfs/DefaultCollection"), 
new NetworkCredential("youruser", "yourpassword")); 

projectCollection.Connect(ConnectOptions.IncludeServices); 

而且這樣:

Uri collectionUri = new Uri("http://server:8080/tfs/DefaultCollection"); 
NetworkCredential netCred = new NetworkCredential("login","password","Server.local"); 
BasicAuthCredential basicCred = new BasicAuthCredential(netCred); 
TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred); 
tfsCred.AllowInteractive = false; 
TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collectionUri, netCred); 
teamProjectCollection.EnsureAuthenticated(); 
+0

您是否嘗試過在使用URI集合名稱.. 。Uri collectionUri = new Uri(「http:// server:8080/tfs/」); –

+0

此外,如果你在一個域中,你應該使用域名的憑據.... NetworkCredential netCred = new NetworkCredential(「login」,「password」,「DomainName」); –

回答

3

希望它可以幫助你。

var tfsCon = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://server:8080/tfs")); 
tfsCon.Authenticate(); 
var workItems = new WorkItemStore(tfsCon); 
var projectsList = (from Project p in workItems.Projects select p.Name).ToList(); 

Uri TfsURL = new Uri(""http://server:8080/tfs""); 
NetworkCredential credential = new NetworkCredential(Username, Password, Domain); 
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(TfsURL, credential); 
collection.EnsureAuthenticated(); 

如果失敗,在這裏你需要在App.config中配置設置默認代理:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.net> 
     <defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy> 
    </system.net> 
</configuration> 
+0

是的。這是工作代碼!謝謝! – user3231442

+0

你能和我們分享哪些選項解決了你的問題?當我嘗試使用與原始帖子完全相同的代碼連接到我們的內部TFS服務器時,我也遇到TF30063錯誤。 –

+0

你正在收到什麼錯誤。 – NullReferenceException