VssConnection SP324098: Your browser could not complete the operation - c#

I am using the following code to try and connect to Azure DevOps and to retrieve a list of work item types, however I keep getting this exception:
BrowserFlowException: SP324098: Your browser could not complete the
operation
There doesn't seem to be much information around this exception. Does anyone know what's going on here? I am using Visual Studio 2017, Enterprise Edition updated to latest build on a Windows 10 updated to latest build machine.
VssClientCredentials credentials = new VssClientCredentials();
VssClientHttpRequestSettings settings = new VssClientHttpRequestSettings
{
AllowAutoRedirect = true
};
VssHttpMessageHandler vssHandler = new VssHttpMessageHandler(credentials, settings);
using (VssConnection connection = new VssConnection(this.CollectionUri, credentials, settings))
{
connection.ConnectAsync().SyncResult();
// Create instance of WorkItemTrackingHttpClient using VssConnection
WorkItemTrackingHttpClient witClient = connection.GetClient<WorkItemTrackingHttpClient>();
var workItemTypes = witClient.GetWorkItemTypesAsync(ProjectName).SyncResult(); ; //exception happens here, I see the login box here too
}

Related

How can I connect to IBM MQ using SSL connection by C# IBMXMSDotnetClient

I am currently able to connect to the IBM MQ server based on jndi binding file with the following c# code
InitialContext ic = null;
IConnectionFactory confac = null;
IConnection conn = null;
ISession sess = null;
IMessageConsumer cons = null;
IDestination dest = null;
try
{
System.Collections.Hashtable env = new System.Collections.Hashtable();
// Set the URL or PATH where the bindings file is located
env[XMSC.IC_URL] = "file://c:/mqbindings/.bindings";
// Initialize the context
ic = new InitialContext(env);
// Lookup for the connection factory name
confac = (IConnectionFactory)ic.Lookup("myconfactoryname");
// Create connection using the details from connection factory
conn = (IConnection)confac.CreateConnection();
// Create an auto ack session
sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Lookup for the destination
dest = (IDestination)ic.Lookup("myqueue");
// ... rest of the code - create consumer or producer
}
catch (XMSException xmsE)
{
// Handle exception
}
However, when the SSL enabled in the IBM MQ Server, it fails to connect. Tried setting different properties (like setting XMSC.IC_PROVIDER_URL to the keystores directory/.jp12 file), but does not seem working.
Exception I got:
IBM.XMS.XMSException: 'CWSMQ0006E: An exception was received during the call to the method ConnectionFactory.CreateConnection: CompCode: 2, Reason: 2059.
I also cannot find any sample code on the official site on how this is working.
Any idea or sample code on this (not necessary in great details, at least, give me some ideas how what I need to set)?

Exception when attempting to authenticate to AD using System.DirectoryServices.Protocols

Want to share with the community a recent exception I encountered after our network folks enabled channel binding on our AD. The change was inspired by KB4520412
My initial code logic was as follows and worked flawlessly up until the recent change.
var cred = new NetworkCredential(credentials.UserId, credentials.Password);
var serverId = new LdapDirectoryIdentifier(host, port);
using var conn = new LdapConnection(serverId, cred);
conn.Bind();
After the change my code started receiving exceptions
"The supplied credential is invalid"
Inner Exception
"80090346: LdapErr: DSID-0C09059A, comment: AcceptSecurityContext error, data 80090346, v3839"
To remedy the exception I changed my code to the below.
using var conn = new LdapConnection(serverId, cred,AuthType.Basic);
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
conn.SessionOptions.FastConcurrentBind();
conn.Bind();
Remedied the exception by implementing a change to the session options as follows.
using var conn = new LdapConnection(serverId, cred,AuthType.Basic);
conn.SessionOptions.ProtocolVersion = 3;
conn.SessionOptions.SecureSocketLayer = true;
conn.SessionOptions.FastConcurrentBind();
conn.Bind();

Why does my C# API work fine on the server but it always fails when I try to call it from any other client machine?

I am having a C# API that takes an Excel sheet (filePath, sheetName) as an input and return the sheet content as the output in JSON form.
The API works fine when I try to test it on my machine that contains windows server 2016 installed on it. But it always fail when I try to send the file path and sheet name from the form.
This is my API Code...
public IHttpActionResult GetSheetData(string filePath, string sheetName)
{
try
{
var connectionString = $#"
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source={filePath};
Extended Properties=""Excel 12.0 Xml;HDR=YES""";
using (var conn = new OleDbConnection(connectionString))
{
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = $#"SELECT * FROM [{sheetName}$]";
using (var DRow = cmd.ExecuteReader())
{
var query = DRow.Cast<DbDataRecord>().Select(row => new
{
name = row[0],
age = row[1],
email = row[2]
});
var JSON = JsonConvert.SerializeObject(query);
return Ok(JSON);
}
}
}
catch (Exception) { return Ok(HttpStatusCode.NotFound); };
}
The JSON result is returned perfectly when I test the API on the Server, But when I try to test it using this form..
It always returns 404 (Not Found).
This is my sample excel sheet data.
Any Ideas?!
I have found the solution to my Issue, and I wanted to share with you.
The Issue was all about the access rights of the IIS.
When I try to access a file on my local machine or in the clients machine, the IIS App Pool must have an access rights on that location.
So, I used the following steps.
Browse to the folder containing the file -to be read-
Right Click the folder and select 'Properties'
Under 'Security' Tab, select Edit.
In the 'Edit' Window select 'Add' -> 'Advanced' -> Find Now
Look up the result names while you find the user related to IIS -[IIS-IUsers]- in my case.
allow access controls to the folder -full access- or -Read and Write- etc...
I Hope this is helpful for you.
Thank you all.

Switch user to root by SSH.NET

I'm using SSH.NET in order to get some informations of an external tape drive. Connecting and executing some basic commands works perfectly fine for me:
ConnectionInfo connNfo = new ConnectionInfo("10.12.2.97", 22, "loginuser",
new AuthenticationMethod[]
{
// Password based Authentication
new PasswordAuthenticationMethod("loginuser","password")
}
);
using (var client = new SshClient(connNfo))
{
client.Connect();
//This command works fine
using (var cmd = client.CreateCommand("ls"))
{
string result = cmd.Execute();
}
}
But now i have to switch to root user in order to execute extended commands i need. Initially logging in with root user is not possible because of security restrictions. Referring to this post How to run commands by sudo and enter password by ssh .net c# i tried this code block:
using (var cmd = ssh.RunCommand("echo 'rootpassword' | sudo -u root -S fsstate"))
{
if (cmd.ExitStatus == 0)
Console.WriteLine(cmd.Result);
else
Console.WriteLine(cmd.Error);
}
But then i always receive this error message:
sudo: unknown user: root
sudo: unable to initialize policy plugin
Update 1:
Working PuTTY commands
What i'm doing wrong here?

How to issue SSH command

I am using C# with SSH.NET.
I want to issue a PWD command but could not find any documentation or help. I do not know how to use 'SshClient' class.
Update:
I also tried experimenting with SshClient class using the below code but it does nothing, neither any error nor any exception.
ConnectionInfo ConnNfo = new ConnectionInfo("FTPHost", 22, "FTPUser",
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod("FTPUser","FTPPass")
}
);
using (var ssh = new SshClient(ConnNfo))
{
ssh.Connect();
if (ssh.IsConnected)
{
string comm = "pwd";
using (var cmd = ssh.CreateCommand(comm))
{
var returned = cmd.Execute();
var output = cmd.Result;
var err = cmd.Error;
var stat = cmd.ExitStatus;
}
}
ssh.Disconnect();
}
Nothing happens. Neither an error nor an exception. On Visual Studio console, i get the below output.
*SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #152199'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server:
'ChannelFailureMessage': 'SSH_MSG_CHANNEL_FAILURE : #0'.*
At ssh.RunCommand method call the program goes in some sleep state (or waits for around 1 minute). sshCommand.Result and sshCommand.Error variables are empty.
Here's a quick example - one way to do it.
string host = "myhost";
string user = "root";
string pwd = "#secret#!"; // Don't use hardcoded plain-text passwords if possible - for demonstration only.
using (PasswordAuthenticationMethod auth = new PasswordAuthenticationMethod(user, pwd))
{
ConnectionInfo connection = new ConnectionInfo(host, user, auth);
using (var ssh = new SshClient(connection))
{
ssh.Connect();
SshCommand sshCommand = ssh.RunCommand("pwd");
Console.WriteLine("Command execution result: {0}", sshCommand.Result);
}
}
Note that if you specify an invalid command (e.g. "pwdxxxx"), you won't get an exception, but an error that will be stored in the SshCommand.Error string.
Note also that this uses SSH PasswordAuthentication, which may not be enabled in your SSH config.
Try looking into the documentation of SSH.NET:
SSH.NET at CodePlex
Code sample for executing a command (recommended)
Help file.CHM

Categories

Resources