• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

No connection could be made because the target machine actively refused it

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    No connection could be made because the target machine actively refused it

    Hi Chaps

    I normally do not post asking for a solution but this one has really driven me mad.

    I am using the HttpWebRequest object in the .NET framework to perform a really normal 'GET' request. The target is on IIS.

    If I run the code through a console application it runs fine and I get a response back.

    If I run it through a web app ( ASP.NET, C#) I get the above exception.

    Two days of googling and troubleshooting has got me nowhere.

    Another thing is, on that same IIS box, there are two more websites which return a response, but the rest give me that exception.

    Any clues? Anybody encountered this problem before ?
    Vote Corbyn ! Save this country !

    #2
    Have you tried using impersonation? Or is it just running as the standard local network service account?

    Comment


      #3
      Originally posted by Durbs View Post
      Have you tried using impersonation? Or is it just running as the standard local network service account?
      Edited, i'd had this before and was trying to think how it was resolved, as i remember, it was caused by the corporate firewall settings on our client machines blocking the call. Worked ok once we uploaded to the dev box that had no such rules applied. Your case sounds different though if other sites on the same box are responding. Do the IIS logs on the box shed any more light?

      Comment


        #4
        Originally posted by Durbs View Post
        Edited, i'd had this before and was trying to think how it was resolved, as i remember, it was caused by the corporate firewall settings on our client machines blocking the call. Worked ok once we uploaded to the dev box that had no such rules applied. Your case sounds different though if other sites on the same box are responding. Do the IIS logs on the box shed any more light?
        I have just published the web page on a proper website and tested it and it works. The same code fails using localhost.

        Even more weird is the fact that requests to some websites work and some do not. You are right that it could be firewall but it could be a combination of firewall and something else.

        I might just leave it at that and wont bother testing on my local machine.
        Vote Corbyn ! Save this country !

        Comment


          #5
          Have you tried disableloopbackcheck and disablestrictnamechecking in the registry?

          Ian

          Comment


            #6
            Originally posted by biondani View Post
            Have you tried disableloopbackcheck and disablestrictnamechecking in the registry?

            Ian
            No I did not try that, but will do so and see if that has any affect. Thanks.
            Vote Corbyn ! Save this country !

            Comment


              #7
              It sounds like a proxy server (I suspect MS ISA) authentication problem on the dev machine:

              Code running in a console application in development: fine because the application is running in the context of a user account (you) that has the correct security context to make a request through the proxy server.

              Code running in an ASP.NET web application in development: doesn't work because the application is running under a system account (NETWORK SERVICE, LOCAL SYSTEM whatever) and the proxy server refuses to serve the request for that user.

              Code running in an ASP.NET web application in the live environment: might sometimes just work without any impersonation / changes from the dev code that didn't previously work and this can be confusing. It depends on the environment setup because sometimes live servers are positioned where they don't make requests through a proxy that requires authentication.

              I seem to remember this exception containing an IP address that tells you specifically which 'target machine' refused the connection.

              Code based impersonation / user context switching is a solution I've used in the past for this problem: e.g. switch to a user account (usually a real windows domain user account specifically created for this purpose i.e. a service account with a password that never expires) that can definitely burrow through the proxy server when making an outbound HttpWebRequest and undo impersonation immediately afterwards. Doing it this way meant the code worked in all environments regardless of infrastructure configuration.
              Moving to Montana soon, gonna be a dental floss tycoon

              Comment

              Working...
              X