Configure SharePoint servers to use proxy with credentials
If your enterprise has a proxy server for all servers with credentials, your SharePoint servers may not be able to connect to Internet. You would probably see errors on RSS Viewer webparts trying to read feeds from Internet.
You need to write some code and deploy a DLL and modify web.config to solve this issue. Here is how to do it:
1) Write a C# class library using following code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace XXXSharePoint
{
public class XXXWebProxy : IWebProxy
{
#region IWebProxy Members
public ICredentials Credentials
{
get
{
return new NetworkCredential(@"account",@"password");
}
set
{
}
}
public Uri GetProxy(Uri destination)
{
return new Uri("https://proxy:port");
}
public bool IsBypassed(Uri host)
{
return false;
}
#endregion
}
}
https://proxy:port is your proxy server’s URL and port, you also need to replace "account","password" with your proxy’s username and password.
2) Compile and deploy the class library (DLL) to SharePoint all servers
3) Add following lines to your SharePoint web application’s web.config, you can use a feature receiver to do the addition.
<defaultProxy enabled="true" useDefaultCredentials="false">
<module type = "YourNameSpace.XXXWebProxy, YourAssembly, …" />
</defaultProxy>
Now do an iisreset and you should be able to access Internet using the proxy from your servers.
Of cause it is not the best practice to hard code your credentials in code. You can leverage ASP.NET's ability of encrypt and decrypt configuration https://msdn.microsoft.com/en-us/library/zhhddkxy.aspx to protect your secrets. You can even create your own encryption solution to achieve this but that’s another topic on its own.
Zewei Song, Ph.D.
MCPD, MCTS: .NET 3.5, MOSS AppDev, Configuration
Enterprise Services, Microsoft Corporation
Comments
Anonymous
December 05, 2010
Hello, where do i must save the .dll??Anonymous
April 21, 2011
Sorry, I missed this comment for a long time...it is recommended to deploy your DLL to GAC.Anonymous
January 09, 2014
<module type = "YourNameSpace.XXXWebProxy, YourAssembly, …" /> Sorry... I cannot understand. Why ", ..." />" ? If i leave it where it is the web.config is wrong, but anyway using <module type = "YourNameSpace.XXXWebProxy, YourAssembly" /> Thank you in advance for your reply!Anonymous
January 09, 2014
<module type = "YourNameSpace.XXXWebProxy, YourAssembly, …" /> Sorry... I cannot understand. Why ", ..." />" ? If i leave it where it is the web.config is wrong, but anyway using <module type = "YourNameSpace.XXXWebProxy, YourAssembly" /> [edit] the connection won't be affected by the dll...pls can you give me some help? [/edit] Thank you in advance for your reply!