How to set a proxy auto-configuration script (.pac) to be used in C#?

PerryC picture PerryC · Jun 30, 2015 · Viewed 8.7k times · Source

I'm starting to write some very simple web-apps in C# and occasionally I get exceptions about not having a proxy configured. I am in a work environment that has a rather strict proxy auto-configuration file (.pac -- Proxy Auto-Config).

Is there a way to tell C# to use that .pac file for proxy settings?

Answer

poprogrammer picture poprogrammer · Jun 30, 2015

.NET can use the default proxy settings of the user running the code. It uses the same settings that are defined for IE. See this article: https://msdn.microsoft.com/en-us/library/dkwyc043%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

You should also see this SO post about MIME types for the PAC file: Using Proxy Automatic Configuration from IE Settings in .Net