previous unencountered "The underlying connection was closed" message with HttpWebRequest

  • Thread starter Thread starter David Cho
  • Start date Start date
D

David Cho

Hi, this is just plain strange. This is my code.

HttpWebRequest request = (HttpWebRequest)
WebRequest.Create("http://www.yahoo.com");

request.Method = "POST";
request.ContentType = "text/xml";
StreamWriter sw = new StreamWriter(request.GetRequestStream()); //error
occurs here

The error is
"The underlying connection was closed: Unable to connect to the remote
server"

I've never had this problem before. This may be a symtom of a deeper
problem I am having. I cannot connect to any remote SQL server. Please
help.
 
David,

Are you doing this in ASP.NET code, or any kind of program on your
machine? If this is ASP.NET code, the code runs under the ASPNET local
account by default, which doesn't have persmissions to access the network.
To get around this, you will have to run under an identity which has the
appropriate rights.

If this is happening for any program on the machine, I would check
things such as network settings, hardware drivers, etc, etc.

Hope this helps.
 
The exactly identical code runs fine as a console application. Already
tried granting admin rights to the ASPNET account with no success.
 
David,

You should not grant administrative rights to the ASPNET account (for a
number of reasons). It would be better if you impersonate a network user
through the use of the <identity> tag in the web.config file for the
application.

Better yet, this page should be in its own directory with its own
web.config file, which would allow just that one page to be run as that user
(and all other code runs under the ASPNET account).
 
Problem solved.

It was the incomplete installation of third party software. In this
case, covenanteyes (covenanteyes.com).
 
Back
Top