see sharp RSS 2.0
# Thursday, 08 May 2014
A small utility that sets the proxy credentials for visual studio.
To install you need to do the following:

1) Copy HannesK.ProxyHelper.dll to IDE directory, i.e.:
    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

2) edit devenv.config 'system.net' section:
    <defaultProxy useDefaultCredentials="false" enabled="true">
        <module type = "HannesK.ProxyHelper.MyProxy, HannesK.ProxyHelper" />
    </defaultProxy>

3) configure appSettings:
    <add key="HannesK.Proxy.User" value="username"/>
    <!-- sorry, only plain password -->
    <add key="HannesK.Proxy.Pass" value="secret"/>
    <add key="HannesK.Proxy" value="http://<server>:<port>"/>

4) open package manager console in VS (with an open solution)
    run the update-package command

The Code:
namespace HannesK.ProxyHelper { using System; using System.Configuration; using System.Diagnostics; using System.Net; public class MyProxy : IWebProxy { private IWebProxy _default; private const string Category = "HannesK.ProxyHelper.MyProxy"; private IWebProxy DefaultProxy { get { return this._default ?? (this._default = WebRequest.GetSystemWebProxy()); } } public ICredentials Credentials { get { var user = ConfigurationManager.AppSettings["HannesK.Proxy.User"]; var pass = ConfigurationManager.AppSettings["HannesK.Proxy.Pass"]; if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pass)) { TraceMessage("using default credentials"); return DefaultProxy.Credentials; } TraceMessage("using credentials: User '{0}', Password 'secret']", user); return new NetworkCredential(user, pass); } //or get { return new NetworkCredential("user", "password","domain"); } set { } } public Uri GetProxy(Uri destination) { var proxy = ConfigurationManager.AppSettings["HannesK.Proxy"]; if (!string.IsNullOrEmpty(proxy)) { TraceMessage("configured proxy is '{0}'", proxy); return new Uri(proxy); } var dproxy = this.DefaultProxy.GetProxy(destination); TraceMessage("default proxy for '{1}' is '{0}'", proxy, destination.AbsoluteUri); return dproxy; } public bool IsBypassed(Uri host) { var rc = DefaultProxy.IsBypassed(host); TraceMessage( "{0} is bypassed:{1}", host.AbsoluteUri, rc); return rc; } private static void TraceMessage(string fmt, params object[] args) { Trace.WriteLine(string.Format(fmt,args), Category); } } }



ProxyHelper.zip (3.83 KB)
Thursday, 08 May 2014 10:46:06 (Mitteleuropäische Sommerzeit, UTC+02:00)  #    -

Archive
<2014 May>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
Any link on this site may lead to an external website that is not under my control and that external website might show an opinion that is not mine.

© Copyright 2017
Hannes Köhler
Sign In
Statistics
Total Posts: 39
This Year: 0
This Month: 0
This Week: 0
Comments: 1
All Content © 2017, Hannes Köhler
DasBlog theme 'Business' created by Christoph De Baene (delarou)