C# 以编程方式授权tfs时出错
我有当地的tfs 2012。在VisualStudio2012上,使用c#,我编写了以编程方式连接到tfs服务器的程序。但我有一个错误: {“TF30063:您无权访问。”}System.Exception{Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException} 我的代码:C# 以编程方式授权tfs时出错,c#,tfs,C#,Tfs,我有当地的tfs 2012。在VisualStudio2012上,使用c#,我编写了以编程方式连接到tfs服务器的程序。但我有一个错误: {“TF30063:您无权访问。”}System.Exception{Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException} 我的代码: Uri collectionUri = new Uri("http://server:8080/tfs"); NetworkCredential
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
你能帮我纠正这个错误吗
另外,我尝试用这种方式连接,但我有相同的错误:
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();
希望对你有帮助
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();
或
如果此处失败,则需要在App.config中配置以设置默认代理:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>
</configuration>
您是否尝试在uri中使用集合名称。。。Uri collectionUri=新Uri(“);如果您在域中,则应使用域名作为凭据….NetworkCredential netCred=新的NetworkCredential(“登录”、“密码”、“域名”);您能与我们分享一下解决您问题的选项吗?我在尝试使用与您的原始帖子几乎完全相同的代码连接到我们的内部TFS服务器时也遇到了TF30063错误。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true"></defaultProxy>
</system.net>
</configuration>