Advertisement
Guest User

Untitled

a guest
Jan 26th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Windows.Forms;
  4.  
  5. namespace BasicProxy
  6. {
  7. public class MyProxy : IWebProxy
  8. {
  9. private readonly string _proxyUri = GetAppSetting("ProxyUri", string.Empty);
  10. private readonly string _proxyUsername = GetAppSetting("ProxyUsername", "user");
  11. private readonly string _proxyPassword = GetAppSetting("ProxyPassword", "password");
  12. private readonly string _proxyDomain = GetAppSetting("ProxyDomain", string.Empty);
  13.  
  14. public ICredentials Credentials
  15. {
  16. get
  17. {
  18. if (string.IsNullOrEmpty(_proxyDomain))
  19. {
  20. return new NetworkCredential(_proxyUsername, _proxyPassword);
  21. }
  22. return new NetworkCredential(_proxyUsername, _proxyPassword, _proxyDomain);
  23. }
  24.  
  25. set { }
  26. }
  27.  
  28. public Uri GetProxy(Uri destination)
  29. {
  30. return new Uri(_proxyUri);
  31. }
  32.  
  33. public bool IsBypassed(Uri host)
  34. {
  35. return false;
  36. }
  37.  
  38. public static string GetAppSetting(string key, string defaultValue = "")
  39. {
  40. var asr = new System.Configuration.AppSettingsReader();
  41. string result;
  42. try
  43. {
  44. result = asr.GetValue(key, typeof(string)).ToString();
  45. }
  46. catch (Exception)
  47. {
  48. result = defaultValue;
  49. }
  50. return result;
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement