I have code on TFS API and its working fine. But when i tried that on different network domain , it got error. Error is -
"TF30063: You are not authorized to access http::///example:8181//tfs//."
But the user AC that i used to connect with TFS server in code, that is ok from VS-2012 and web URLs but not from TFS API.
is there any dependency for different domain on TFS authentication?
code -
this.collection_string = "http:://abcd:8080/tfs/" + collectionName;
this.projectCollection = new TfsTeamProjectCollection(new Uri(this.collection_string), new NetworkCredential("username", "password", "domain"));
projectCollection.EnsureAuthenticated();
this.versionControllerServer = (VersionControlServer)this.projectCollection.GetService(typeof(VersionControlServer));
this.buildServer = (IBuildServer)this.projectCollection.GetService(typeof(IBuildServer));
Console.WriteLine("Connected successfully to the server");
Try to access your TFS using IP address in your TFS URL instead of it's name. Actually, i faced the same issue earlier and it was resolved by accessing it via IP address.
Another possible solution is add a Host entry of your TFS Server in your local machine.
Related
We have a WebAPI project that exposes a few controllers doing tasks with TFS. We usually connect like this:
var server =
new Microsoft.TeamFoundation.Client.TfsConfigurationServer(new Uri("http://XXX"));
server.EnsureAuthenticated();
My understanding of this is: It works because somehow, my IIS express runs the application under my account. Somehow the TfsConfigurationServer can read my credentials and use them when querying/writing over TFS.
Now, the problem comes when I try to host this in a real webserver. Comes back with:
"TF30063: You are not authorized to access http://XXX"
I have activated Windows Authentication, so if I print:
User.Identity.Name -> (domain\\my_user).
Even being there my username, it does not seem to be enough. I assumed the TfsConfigurationServer class can't get the credentials, so I've tried to be more explicit:
new TfsConfigurationServer(new Uri("XXX"), CredentialCache.DefaultNetworkCredentials);
Didn't work either. I was assuming that, given that I have Windows Authentication activated and Anonymous deactivated, DefaultNetworkCredentials would work. Reading more I've found also:
var id = (WindowsIdentity)User.Identity;
using (id.Impersonate())
{
return myOperation.CallMethod();
}
But same result. Inside CallMethod() I was calling again TfsConfigurationServer with the DefaultNetworkCredentials. The impersonation seems to be working fine, but authentication to TFS fails anyway.
How can I provide the credentials to TFS from the currently logged in user in the server via Windows Auth?. How does it work in local?.
Note: I have been reading also about TFS Impersonation (https://blogs.msdn.microsoft.com/taylaf/2009/12/04/introducing-tfs-impersonation/). My problem is that it seems to require some permissions set in the server, I'd love to mimic that behavior without using this technique, not sure if that's possible.
Give a try with below code:
var tfsCredentials = new TfsClientCredentials(System.Net.CredentialCache.DefaultCredentials, true);
TfsTeamProjectCollection teamCollection = new TfsTeamProjectCollection(new Uri("http://tfssite.com/tfs/" + Collection), tfsCredentials);
I am using below code to connect my tfs where executing machine is part of domain.
But when I try the same code in different machine (not in domain, but part of work group) getting unauthorized access error.
But in the same machine (where getting error), I am able to connect TFS with same account used in code via visual studio.
var tfsServer = new TfsConfigurationServer(
new Uri(ConfigurationManager.AppSettings["TFS_URI"]),
new NetworkCredential(
ConfigurationManager.AppSettings["TFSUserName"],
ConfigurationManager.AppSettings["TFSPassword"],
ConfigurationManager.AppSettings["Domain"]));
It's going to depend on getting the network credential specified properly. I'd suggest using Fiddler to take a look at what VS is sending and what your code is sending.
Here is a bit of background on the setup:
I have a server called "File-Serv".
I have an NS entry that redirects clients.mydomain.com to the ip address of the modem which in turns forwards the request to the computer (this is all working perfectly so far)
I have apache running on port 80 and one IIS site running on port 8080
I installed TFS and changed the binding of the TFS site to use port 8081 so that it doesn't clash with the rest.
I installed team explorer on the server and was able to connect to TFS and add a project, etc.
The problem is now that i want to access TFS from all other computers on the network and more importantly still access TFS if i'm not connected to the local network but i can't
What i have tried is to change the notification url to clients.mydomain.com and change the binding on IIS to match. when i go to clients.mydomain.com:8081/tfs/web it asks me for a username and password
I do not have active directory installed and i have created users for all the users needed on the server but when whatever combination i put for username/password, i can never ever log in.
I've tried the following usernames with no success:
Administrator
File-Serv\Administrator
clients.mydomain.com\Administrator
I'm really not sure what i'm missing here.. I have read forums upon forums without any resolution. Help!
P.S. This is my first question on stackoverflow after using the site religiously for 2 years now!
I found number of sample of the TFS Api using the TFS Url to get the tfs server.
Is there a way to use the default server configured on the machine.
I don't want to put the URL in all the dll I write or in all the script.
You can also look at the list of locally known TFS service in the windows registry: How do I get a list of Team Foundation Server Servers available on my PC?
Obviously you need to get the machine name from somewhere I suggest if its not found in config or some other mechanism you try some of these bits of code to get the machine name and try to connect to the local machine on the default port if not specified elsewhere
string name = Environment.MachineName;
string name = System.Net.Dns.GetHostName();
string name = System.Windows.Forms.SystemInformation.ComputerName;
string name = System.Environment.GetEnvironmentVariable(“COMPUTERNAME”);
This is an absolute beginner question in TFS SDK:
I am trying to connect to TFS server using the code
TeamFoundationServer teamFoundationServer =
TeamFoundationServerFactory.GetServer(X);
X is server name
I am getting an error like
TF249051: No URL can be found that corresponds to the following server name: X
Verify that the server name is correct.
However I am able to connect to the TFS server from VS2010 using Team->Connect to TFserver menu option
The TeamFoundation Server Factory is deprecated. You should use TeamFoundationProjectCollection.
And, yes, under TFS 2010, you'll need the folder.