The underlying connection was closed Error in ASP.NET

The underlying connection was closed

Problem

You will encounter this problem if your machine is sitting behind a firewall proxy and you try to invoke the GetResponse method of the WebRequest class (WebRequest.GetResponse()). I have seen many posts on the issue but none worked. Many solutions suggest editing the machine.config file, but to no avail. I have gone to such broad tangents looking for a solution to this problem and found a very simple and effective solution and it all lies in including just a few lines in your web.config file.

Error Message

The underlying connection was closed: Unable to connect to the remote server.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server.

Resolution

Just include the following lines in your web.config file.

<system.net>
    <defaultProxy
>
        <proxy proxyaddress="http://your.proxy.server:80&quot; bypassonlocal="true"/>

    </defaultProxy
>
</system.net>

This should fix the problem and put an end to a previously long lasting headache.

That’s all folks and happy programming

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s