TFS Server Credential Error - c#

I want to collect a List of Project in TFS 2013 Using API .
I am Putting URL and User name and Password, (Server properly Connected Browser).
I have collected all Project with TFS Collection List. But my API Call does not working on client. What is the problem?
Here My Sample Code
Uri configurationServerUri = new Uri(URL);
NetworkCredential credentials = new NetworkCredential(UserName, Password);
teamProjectCollection = new TfsTeamProjectCollection(configurationServerUri, credentials);// Set Connection
teamProjectCollection.EnsureAuthenticated();
//CatalogNode configurationServerNode = teamProjectCollection.TeamFoundationServer.TfsTeamProjectCollection.CatalogNode;
//li.Add(configurationServerNode.Resource.DisplayName);
TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri);
ITeamProjectCollectionService tpcService = configurationServer.GetService<ITeamProjectCollectionService>();
foreach (TeamProjectCollection tpc in tpcService.GetCollections())
{
list.Add(tpc.Name);
}

Related

not able to connect to the TFS using asp.net MVC application

trying to connect to the TFS server using below code and getting exception.
NetworkCredential credentials = new NetworkCredential("username", "password");
credentials.Domain = "domain";
BasicAuthCredential basicCredentials = new BasicAuthCredential(credentials);
TfsClientCredentials cred = new TfsClientCredentials(basicCredentials);
cred.AllowInteractive = false;
var _tfsTeamProjectCollection = new TfsTeamProjectCollection(new Uri("mytfsurl));
_tfsTeamProjectCollection.Authenticate();
Exception : The request was aborted: Could not create SSL/TLS secure channel.
same code works fine with the console application.

Amazon S3 Unable to find credentials in C#

I'm trying to upload an image file to aws s3 storage and get back that image URL. I'm using secret key and access key to create credentials. But when the program runs it it says
"Unable to find credentials" .
Here is my code which i used.
public string sendMyFileToS3(string from,string to, string bucketName, string fileName)
{
BasicAWSCredentials awsCreds = new BasicAWSCredentials(bucketName, fileName);
AmazonS3Client client = new AmazonS3Client(awsCreds);
TransferUtility utility = new TransferUtility(client);
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
request.BucketName = bucketName;
request.Key = fileName;
request.FilePath = from;
utility.Upload(request);
string urlString = "";
GetPreSignedUrlRequest request1 = new GetPreSignedUrlRequest
{
BucketName = bucketName,
Key = fileName,
Expires = DateTime.Now.AddYears(2)
};
urlString = client.GetPreSignedURL(request1);
Console.WriteLine(urlString);
File.Move(from, to);
return urlString ;
}
In order to create an S3 Client you need to provide your credentials, the region and endpoint:
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "s3.amazonaws.com";
config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("us-east-1");
client = new AmazonS3Client(credentials, config);
The possible regions are listed here, and depend on where you created your bucket being us-east-1 the default value.
While the possible endpoints are this three:
s3.amazonaws.com
s3-accelerate.amazonaws.com
s3-accelerate.dualstack.amazonaws.com
The first one being the standard one since the others need you to configure your bucket like it's explained here.
I am going to take a guess and say you have a conflict between the credentials your app is using and other credentials you may have installed onto your dev or test machine, i.e. in the credentials file or your app.config.
I would check and make sure you are only using a single method to provide those credentials to the program.
THis link shows the priority the SDK will look for the credentials:
http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

Access SharePoint online using client object model- Forbidden error

I tried to Create a new list item using client object model. I have created an asp.net application to do the task. It works if I pass the URL of SharePoint server which is installed in my machine.
But if I give my SharePoint online URL it is not working as below code shows. I get "The remote server returned an error: (403) Forbidden. " error.
Any idea?
ClientContext context = new ClientContext("https://xxx.sharepoint.com/SitePages/");
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = result.City;
newItem["Body"] = result.State;
newItem.Update();
context.ExecuteQuery();
if you are trying to get a Context object from SharePoint Online you have to put in the right Credentials, as for SharePoint Online you should use the SharePointOnlineCredentials Class
A possible Authentication Method can be look like this:
private void AutheticateO365(string url, string password, string userName)
{
Context = new ClientContext(url);
var passWord = new SecureString();
foreach (char c in password.ToCharArray()) passWord.AppendChar(c);
Context.Credentials = new SharePointOnlineCredentials(userName, passWord);
var web = Context.Web;
Context.Load(web);
Context.ExecuteQuery();
}
I would imagine you just have to supply your login credentials and it should work:
clientContext.Credentials = new NetworkCredential("Username", "Password", "Domain");
You'll need to including System.Net:
using System.Net;

Connect to MS Dynamics CRM 2011 Desktop CrmConnection

My client is using the hosted edition, and not the online version, of Dynamics CRM 2011. Using my C# code, how would I obtain the user name, password, URL and device ID to authenticate? Using the CRM 2011 online, I can connect using this code. I believe device ID is hard coded.
CrmConnection crmConnection = CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password=
{2};DeviceID=enterprise-ba9f6b7b2e6d; DevicePassword=passcode;", url, username, password));
OrganizationService service = new OrganizationService(crmConnection);
var xrm = new XrmServiceContext(service);
return xrm;
Hosted version (OnPremise) relies on Active Directory authentication (DOMAIN\USERNAME), so you need to add Domain to your connection string and remove DeviceID and DevicePassword (they are necessary only for CRM Online using LiveId authentication)
The code will be:
CrmConnection crmConnection =
CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain));
Try just delete deviceid and devicepassword. Also check this article that describes how to use CrmConnection class.
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
/This URL needs to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
if (Context.User.Identity.IsAuthenticated)
{
string EUserName = Context.User.Identity.Name;
string WinUserName = WindowsIdentity.GetCurrent().Name;
UserName.InnerText = EUserName;
}
}
Also add references
**microsoft.crm.sdk.proxy**
**microsoft.xrm.sdk**

SignalR C# Client 407 Proxy Authentication Required

I'm trying to build a C# SignalR app (console app on the server, winforms app on the client), and it works great (in Visual Studio) when both the client and server are on the same PC, but when I deploy the server and repoint the client to the server, I'm getting a "407 Proxy Authentication Required" exception when it tries to start.
This is my code...
var _connection = new HubConnection("http://www.redacted.com:8088/");
var _hub = _connection.CreateProxy("MyHub");
_connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
MessageBox.Show(string.Format("Could not connect - {0}", task.Exception.ToString()));
}).Wait();
I noticed that HubConnection has a Credentials property, and so I figured I'd try replacating some code I've used with WebServices when dealing with proxies (shown below, where I just make an HTTP request out and then pick up the proxy settings and credentials from that), but I get the same exception.
var _connection = new HubConnection("http://www.redacted.com:8088/");
var req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
var proxy = new WebProxy(req.Proxy.GetProxy(req.RequestUri).AbsoluteUri) {UseDefaultCredentials = true};
_connection.Credentials = proxy.Credentials;
var _hub = _connection.CreateProxy("MyHub");
_connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
MessageBox.Show(string.Format("Could not connect - {0}", task.Exception.ToString()));
}).Wait();
This is required for some work I'm doing for a client where they want their local PCs to be able to receive messages from a remote system that's hosted outside the company.
Thanks!
Try to set the DefaultWebProxy:
WebProxy wproxy = new WebProxy("new proxy",true);
wproxy.Credentials = new NetworkCredential("user", "pass");
WebRequest.DefaultWebProxy = wproxy;

Categories