Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Windows.Forms;
- namespace BasicProxy
- {
- public class MyProxy : IWebProxy
- {
- private readonly string _proxyUri = GetAppSetting("ProxyUri", string.Empty);
- private readonly string _proxyUsername = GetAppSetting("ProxyUsername", "user");
- private readonly string _proxyPassword = GetAppSetting("ProxyPassword", "password");
- private readonly string _proxyDomain = GetAppSetting("ProxyDomain", string.Empty);
- public ICredentials Credentials
- {
- get
- {
- if (string.IsNullOrEmpty(_proxyDomain))
- {
- return new NetworkCredential(_proxyUsername, _proxyPassword);
- }
- return new NetworkCredential(_proxyUsername, _proxyPassword, _proxyDomain);
- }
- set { }
- }
- public Uri GetProxy(Uri destination)
- {
- return new Uri(_proxyUri);
- }
- public bool IsBypassed(Uri host)
- {
- return false;
- }
- public static string GetAppSetting(string key, string defaultValue = "")
- {
- var asr = new System.Configuration.AppSettingsReader();
- string result;
- try
- {
- result = asr.GetValue(key, typeof(string)).ToString();
- }
- catch (Exception)
- {
- result = defaultValue;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement