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.
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'm trying to set up a TFS VCS root in TeamCity and I'm getting TF30063: You are not authorized to access http://tfsserver.com:8080/tfs. I know that the account that I'm using has access to the TFS server because it's the same one I use for Visual Studio and it works fine.
I checked the logs and they say that the request is returning a 500 error. For not authorized I would have expected a 401. Has anybody seen something like this before?
I don't do much with Team City but I would expect that it wants a URL to either a Collection or Team Project (which is not what the URL in your question is).
http://tfsserver.com:8080/tfs/DefaultCollection
or
http://tfsserver.com:8080/tfs/DefaultCollection/MyProject
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.
I have installed TFS 2012 Express on my computer but I can't get TFS web access portal to work. If I try to view a page with work items I get error:
TF400893: Team Foundation Server services are not available.
This is most likely caused by a network error.
Please check your connection and try again.
It's weird because other parts of the TFS web portal works (e.g. source) so I don't think it's network error. If I connect to the TFS server from Visual Studio everything is working, so I suppose TFS service is running.
I tried to reinstall TFS, but it didn't help :-(
Any ideas what can be wrong?
Try an other browser. I have used Opera and got the error. Using IE should work.
Try changing the account from Applicaiton Tier on TFS Administration Console to your current domain and user info. The default value is NT AUTHORITY.
You should check for any firewalls or other IPS devices between the browser and the application tier for SQL injection attack rules. WIQL being sent from the browser in the AJAX request looks far too much like regular SQL so gets canned by such rules.
As we were experiencing this issue where I work, I decided to take a network packet capture of the browser traffic on a machine experiencing the problem. This yielded a whole bunch of TCP retransmits on the packet containing the plain-text WIQL. Upon presenting this evidence to the company's network team, they located the offending IPS rule which was triggering on these packets, disabled it for packets targeting the TFS Application tier and the problem was solved.
I just got the same error while adding a comment to a work item which included a SQL Statement to drop some tables.
After changing my language to not include explicit T-SQL "DROP TABLE" syntax, I was able to add the comment. My guess is something trying to prevent SQL injection.
I am trying to create a spsite of object for sharepoint search but i am getting exception in production as website not found
SPSite site = new SPSite("sitename");
ServerContext scon = ServerContext.GetContext(site);
SearchContext srchcontext = SearchContext.GetContext(scon);
Scopes sc = new Scopes(srchcontext);
It throws exception site not found i have checked the name of site it exixts.
Any Help??
Check that you are building against the correct target. I.e. x86 vs x64.
I get this error when I build against x86 and try and run against x64.
Do you have your permissions set up correctly? Check out this conversation...
http://social.msdn.microsoft.com/Forums/ja-JP/sharepointdevelopment/thread/4d923b6a-d423-4c42-82dd-3315872db9cc
You need to ensure (taken from the above) that:
The user is a server farm
administrator.
The user has Read and Write permissions on the content database.
The user is a site collection administrator.
The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.
You should also ensure that you are using an ip address you can hit from both your local box, and the server that you are running the program on.
Before executing the program, ping the webaddress from the cmd prompt.
Another way to test it is to open up the exact webaddress in a browser from the box that you are executing the program.
It's possible you are trying to hit an internal site from a server which is not on the same domain.
And finally, as it says in the MSDN Documentation you shouldn't be using "SiteName" but rather ensure that you are using "SiteAbsoluteUrl".
If you create a console application and try the same code there, the same code works. You have to add application to IIS and change the app pool identity. I did the same and it worked for me.