The docs indicate, that the default Proxy-Setup for the HttpClient will be determined through the presence of environmental variables and/or the system wide proxy settings.
I set the proxy-auth credentials like this:
setx http_proxy http://user:password#proxyIP:proxyPort/, and to be sure rebootet the system.
Since the Windows proxy-settings dialog does not allow to set username and password, i included there the proxy address and port.
Now i try to read them back though the CredentialCache with my C# app.
However the CredentialCache.DefaultCredentials are still empty and the proxy blocks and responds with 407 exceptions. Which is correct, since i cannot pass the credentials.
How do i have to setup the username and password to be able to read them from the CredentialCache?
I would like to be able to go this way, since very old code, long time ago shipped to customers, using a WebRequest object together with this settings is able to go through.:
UseDefaultCredentials = true;
Proxy = WebRequest.GetSystemWebProxy();
Proxy.Credentials = CredentialCache.DefaultCredentials;
Thats why i would like to also be able to write somethin to Windows that in turn gets read out of the Cache.
Related
In using IBMMQDotnetClient v9.2.0.1 in .NET Core, I attempt to connect to a client using
private MQQueueManager Connect()
{
System.Collection.Hashtable properties = new System.Collections.Hashtable();
properties.Add(MQC.USER_ID_PROPERTY, "username");
properties.Add(MQC.PASSWORD_PROPERTY, "password");
// more settings below
return new MQQueueManager(QueueManagerName, properties);
}
The issue is this still attempts to pass my personal windows credentials even after having set the userid and password when configuring the queue manager properties. How do I ensure that the credentials passed by the application replace my personal windows creds when running the application.
Edit:
For more context, the output options are configured as:
public static readonly int OUTPUT_OPTIONS = MQC.MQOO_OUTPUT;
I am not sure if there can be other options that can ensure the passed creds are used as opposed to the windows creds.
For anyone in the future that runs into a similar situation I wanted to give an update on my resolution. I ended up running the IIS server with the credentials that were authenticated with MQ as opposed to a Network Service and this fixed the issue. This allowed me to use the queue manager that had already been set up, without changing its settings in any way.
As I understand it, the FtpWebRequest.Proxy property denotes an HTTP proxy. I have to issue FTP requests to an external server via an FTP proxy.
The only way I've got this to work so far is by creating a script which uses the Windows FTP command and downloading that way.
Is it possible to use the FtpWebRequest to download files via an FTP proxy?
Here's code I've used before, I should caveat I've only tested this against a Checkpoint firewall so the format USER and PASS commands maybe different for your FTP Proxy. Your system administrator will know the correct format.
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(
new Uri("ftp://FTP PROXY HOST/actual/path/to/file/on/remote/ftp/server"));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential
("REMOTE FTP USER#FTP PROXY USER#REMOTE FTP HOST"
, "REMOTE FTP PASSWORD#FTP PROXY PASSWORD");
If the FTP proxy allows specifying all information about the target via USER and PASS commands, you can use the Credentials property.
Typically, you specify the username in a form user#proxyuser#host and password in a form password#proxypassword:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://proxy/path");
request.Credentials = new NetworkCredential("user#proxyuser#host", "password#proxypassword");
If the proxy does not require authentication, use a form user#host and password:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://proxy/path");
request.Credentials = new NetworkCredential("user#host", "password");
But your proxy server may also require a different syntax, like:
separate USER commands for proxy user and target host user
OPEN command
SITE command
In these cases, you cannot use the FtpWebRequest. You must use a 3rd party FTP client library instead.
For example with WinSCP .NET assembly, you can use:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "host",
UserName = "user",
Password = "password",
};
// Configure proxy
sessionOptions.AddRawSettings("ProxyHost", "proxy");
sessionOptions.AddRawSettings("FtpProxyLogonType", "2");
sessionOptions.AddRawSettings("ProxyUsername", "proxyuser");
sessionOptions.AddRawSettings("ProxyPassword", "proxypassword");
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
}
For the options for the SessionOptions.AddRawSettings, see raw settings.
Easier is to configure the proxy settings in WinSCP GUI and have it generate C# FTP code template for you.
Note that WinSCP .NET assembly is not a native .NET library. It's rather a thin .NET wrapper over a console application.
(I'm the author of WinSCP)
If you have the budget for it - Dart do some great classes for this:
http://www.dart.com/
or specifically
http://www.dart.com/ptftpnet.aspx
I know this is way past the due date, but yes, I'm able to get FtpWebRequest to work with an ftp proxy by using the old tricks of setting the URL to
"ftp://your.proxy.server/theFileToDownload")"
Then set your network credential to
username="ftpUserName#ftp.realserver.com"
and
password="password".
I remembered doing this back in the bad old WININET days, and sometimes the old tricks are still the best tricks.
YMMV of course.
They claim it is possible to list, listdetails, and download through a proxy. However I could not get this to work with an isa firewall. So I disabled the default proxy in my app.config and added an application rule for ForeFront/ISA client. To do this I created a file c:\programdata\microsoft\firewall client 2004\application.ini with the contents:
[applicationName]
DisableEx=0
Disable=0
NameResolution=R
where applicationName is the running exe minus the .exe extension.
At my company we have recently set up a TeamFoundation proxy to our TeamFoundationServer. I have written a C# app, that connects to the TFS to query various things. Now, I want the app to support connection over the TFS proxy as well. As I am not really familiar with TFS, I am having some difficulties. Ideally, I want the application to only "know" the TFS proxy and have it act just like the normal TFS. Is this even possible?
What I am doing is something like this:
TfsTeamProjectCollection projects =
new TfsTeamProjectCollection(new Uri(serverUriString,
new NetworkCredential(username, password, domain));
This works fine if serverUriString is the TFS (e.g. "http://MyTfs:8080"). When I substitute this with the TFS proxy (e.g. "http://MyTfsProxy:8081") I get some unspecific TeamFoundationServiceUnavailableException, where at the end it states that a http 404 error occurred. The 404 doesn't make much sense to me, I am able to ping the server, I can connect to it from the browser and Visual Studio acceppts it as well. Do I need to set a connection to the TFS AND the proxy? If yes, how do I do that?
The AddProxy() method is used to register a list of proxy servers with the TFS server, so that clients can automatically detect & use a proxy server.
If you just want to configure your client to use a proxy server, there is no property to do this. You have to set a registry key or an undocumented environment variable.
For TFS2008 clients, the registry key is:
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\TeamFoundation\SourceControl\Proxy]
"Enabled"="True"
"Url"="http://someproxy:8081"
For TFS2010 clients, the registry key is:
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Proxy]
"Enabled"="True"
"Url"="http://someproxy:8081"
In either TFS version, you can set the undocumented environment variable:
System.Environment.SetEnvironmentVariable("TFSPROXY",http://someproxy:8081);
You can do this:
TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(serverName));
server.EnsureAuthenticated();
var versionControlServer = server.GetService<VersionControlServer>();
versionControlServer.ConfigureProxy(proxyName);
As I understand it, the FtpWebRequest.Proxy property denotes an HTTP proxy. I have to issue FTP requests to an external server via an FTP proxy.
The only way I've got this to work so far is by creating a script which uses the Windows FTP command and downloading that way.
Is it possible to use the FtpWebRequest to download files via an FTP proxy?
Here's code I've used before, I should caveat I've only tested this against a Checkpoint firewall so the format USER and PASS commands maybe different for your FTP Proxy. Your system administrator will know the correct format.
FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(
new Uri("ftp://FTP PROXY HOST/actual/path/to/file/on/remote/ftp/server"));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential
("REMOTE FTP USER#FTP PROXY USER#REMOTE FTP HOST"
, "REMOTE FTP PASSWORD#FTP PROXY PASSWORD");
If the FTP proxy allows specifying all information about the target via USER and PASS commands, you can use the Credentials property.
Typically, you specify the username in a form user#proxyuser#host and password in a form password#proxypassword:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://proxy/path");
request.Credentials = new NetworkCredential("user#proxyuser#host", "password#proxypassword");
If the proxy does not require authentication, use a form user#host and password:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://proxy/path");
request.Credentials = new NetworkCredential("user#host", "password");
But your proxy server may also require a different syntax, like:
separate USER commands for proxy user and target host user
OPEN command
SITE command
In these cases, you cannot use the FtpWebRequest. You must use a 3rd party FTP client library instead.
For example with WinSCP .NET assembly, you can use:
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "host",
UserName = "user",
Password = "password",
};
// Configure proxy
sessionOptions.AddRawSettings("ProxyHost", "proxy");
sessionOptions.AddRawSettings("FtpProxyLogonType", "2");
sessionOptions.AddRawSettings("ProxyUsername", "proxyuser");
sessionOptions.AddRawSettings("ProxyPassword", "proxypassword");
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Your code
}
For the options for the SessionOptions.AddRawSettings, see raw settings.
Easier is to configure the proxy settings in WinSCP GUI and have it generate C# FTP code template for you.
Note that WinSCP .NET assembly is not a native .NET library. It's rather a thin .NET wrapper over a console application.
(I'm the author of WinSCP)
If you have the budget for it - Dart do some great classes for this:
http://www.dart.com/
or specifically
http://www.dart.com/ptftpnet.aspx
I know this is way past the due date, but yes, I'm able to get FtpWebRequest to work with an ftp proxy by using the old tricks of setting the URL to
"ftp://your.proxy.server/theFileToDownload")"
Then set your network credential to
username="ftpUserName#ftp.realserver.com"
and
password="password".
I remembered doing this back in the bad old WININET days, and sometimes the old tricks are still the best tricks.
YMMV of course.
They claim it is possible to list, listdetails, and download through a proxy. However I could not get this to work with an isa firewall. So I disabled the default proxy in my app.config and added an application rule for ForeFront/ISA client. To do this I created a file c:\programdata\microsoft\firewall client 2004\application.ini with the contents:
[applicationName]
DisableEx=0
Disable=0
NameResolution=R
where applicationName is the running exe minus the .exe extension.
I'm writing a small C# application that will use Internet Explorer to interact with a couple a websites, with help from WatiN.
However, it will also require from time to time to use a proxy.
I've came across Programmatically Set Browser Proxy Settings in C#, but this only enables me to enter a proxy address, and I also need to enter a Proxy username and password. How can I do that?
Note:
It doesn't matter if a solution changes the entire system Internet settings. However, I would prefer to change only IE proxy settings (for any connection).
The solution has to work with IE8 and Windows XP SP3 or higher.
I'd like to have the possibility to read the Proxy settings first, so that later I can undo my changes.
EDIT
With the help of the Windows Registry accessible through Microsoft.Win32.RegistryKey, i was able to apply a proxy something like this:
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:8080");
But how can i specify a username and a password to login at the proxy server?
I also noticed that IE doesn't refresh the Proxy details for its connections once the registry was changed how can i order IE to refresh its connection settings from the registry?
Thanks
For IE, you can use the same place in the registry. Just set ProxyServer="user:password#127.0.0.1:8080" however firefox completely rejects this, and does not attempt to connect.
Here's how I've done it when accessing a web service through a proxy:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUrl);
WebProxy proxy = new WebProxy(proxyUrl, port);
NetworkCredential nwCred = new NetworkCredential(proxyUser, proxyPassword);
CredentialCache credCache = new CredentialCache();
credCache.Add(proxy.Address, "Basic", nwCred);
credCache.Add(proxy.Address, "Digest", nwCred);
credCache.Add(proxy.Address, "Negotiate", nwCred);
credCache.Add(proxy.Address, "NTLM", nwCred);
proxy.Credentials = credCache;
proxy.BypassProxyOnLocal = false;
request.Proxy = proxy;