mekar10
mekar10

Reputation: 651

How can I detect my client using proxy?

I am developing a windows application. It calls a webservice. But some of my clients use a proxy. For proxy-using clients I want to show a message box and redirect to application settings WinForm for proxy credential ınfo.

So how can detect a client is using proxy? (I am using C#)

Upvotes: 0

Views: 1726

Answers (1)

Roman Melnyk
Roman Melnyk

Reputation: 1097

Just check by WebRequest.DefaultWebProxy

string sampleURL = "http://proxy.example.com";
bool useProxy = !string.Equals(System.Net.WebRequest.DefaultWebProxy.GetProxy(new Uri(sampleURL)), sampleURL);    
Console.WriteLine( useProxy ? "Yes" : "No");

Or by simple cast check:

if (System.Net.WebRequest.DefaultWebProxy as System.Net.WebProxy != null) {}

Upvotes: 3

Related Questions