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);
Related
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.
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've got ServiceStack working nicely on the server and with a Windows test client, and now need to get it working in my Mono For Android application.
I've downloaded the following:
ServiceStack.Common.dll
ServiceStack.Interfaces.dll
ServiceStack.Text.dll
from the github tip, and added references to these in my Mono for Android project.
However, we need to use authentication, so need the ServiceStack.ServiceInterface.Web namespace to be available for the client, so I can do the following:
var c = new JsonServiceClient("http://localhost:53434");
var authResponse = c.Get(new Auth { UserName = "myusername", Password = "password", RememberMe = true });
Looking at my working test client, Auth is defined in ServiceStack.ServiceInterface.dll, so presumably I need to get hold of this DLL, or its source and compile it in my project.
Am I on the right lines here, or is there a simpler way to set things up? I've searched around but can't find a good resource on how to use ServiceStack with Mono For Android - if there is one, please feel free to point me to it!
I note this StackOverflow indicates I'm on the right lines - all I might need is ServiceStack.ServiceInterface.dll compiled for Mono For Android.
James
You shouldn't have to compile the server ServiceStack.ServiceInterface.dll for use in any client library as there is a copy of the Auth DTOs is also available in the ServiceStack.Common.dll client library at ServiceStack.Common.ServiceClient.Web.AuthDtos.cs.
This is possible since both server and client DTOs generate the same wireformat.
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.
I've been experimenting with ASP.Net MVC, and have come across a problem that is probably not specifically MVC related. But I cannot get the authentication in the default MVC application (the one created by the wizard when you create a new MVC project) to work properly under IIS 7 on Windows 7.
If I run under the Visual Studio environment, it works, but if I switch the settings to run under IIS instead, I get the following exception trying to submit the login or registration:
Failed to generate a user instance of
SQL Server due to failure in
retrieving the user's local
application data path. Please make
sure the user has a local user profile
on the computer. The connection will
be closed.
I believe that this is because the website runs under my own account in Visual Studio, but under the IUSR account in IIS. Google searches on the exception message have been unhelpful so far.
So, can one create a local user profile for the IUSR account? If so, how? Is there something else I should be doing to get the SQLExpress engine to work under the anonymous account in IIS 7?
I also tried configuring the IIS website to use my account, but since this is my home machine, my account doesn't have a password, and it appears that IIS won't let a website be configured to use an account without a password. Or, since this is my first experience with IIS 7, and configuration feels very different than IIS 5/6, I am just missing the right setting that will let me configure the account to use for anonymous access.
EDIT: Some additional information. If I empty the App_Data folder and try again from IIS, SQLExpress attempts to create my database and fails, but the exception message has further information with the following suggestions.
SQLExpress database file auto-creation
error:
The connection string specifies a
local Sql Server Express instance
using a database location within the
applications App_Data directory. The
provider attempted to automatically
create the application services
database because the provider
determined that the database does not
exist. The following configuration
requirements are necessary to
successfully check for existence of
the application services database and
automatically create the application
services database:
If the applications App_Data directory does not already exist, the
web server account must have read and
write access to the applications
directory. This is necessary because
the web server account will
automatically create the App_Data
directory if it does not already
exist.
If the applications App_Data directory already exists, the web
server account only requires read and
write access to the applications
App_Data directory. This is necessary
because the web server account will
attempt to verify that the Sql Server
Express database already exists within
the applications App_Data directory.
Revoking read access on the App_Data
directory from the web server account
will prevent the provider from
correctly determining if the Sql
Server Express database already
exists. This will cause an error when
the provider attempts to create a
duplicate of an already existing
database. Write access is required
because the web server accounts
credentials are used when creating the
new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user
profile. See the readme document for
details on how to create a local user
profile for both machine and domain
accounts.
I've pretty extensively confirmed that the first three suggestions have been satisfied. The fourth seems to be the cause of my problems, but I can't figure out how to do that. And although the suggestion claims there is a readme document that describes it, I have not been able to find that document.
I got this problem as well running under medium trust. The process that creates the database requires at least High trust. You can check this by looking in your Web.Config for
<trust level="TrustLevel" />
If there is no trust specified in your Web.Config, try adding it and set it to either Full or High. If this doesn't work, there is a machine.config in your IIS which you would need to modify.
That being said, the best route I have found to solve this is to just use aspnet_regsql.exe to create the necessary tables and then change the connection string in your Web.Config to look at it directly.
I solved "The directory 'LocalApplicationData' does not exist." error when running an SSIS package through an SQL Job by ensuring the SQL SSIS service and SQL Server Agent service were running under the same account as the swql job was set to use!
This in my case was a domain account.
Solution: Try UNINSTALLING any updates before you started experiencing the issue. I spent countless hours - wasted hours that I will never get back in my life - reading and following every solution possible without success. I uninstalled all SQL Server updates and now everything works fine.