HTTP status 401: Unauthorized when connectiong to webservice - cannot authenticate from localhost

PatrickK_W
PatrickK_W used Ask the Experts™
on
Hi. Weird one. We have a webservice secured in an asp.net website that requires windows authentication. This has been working for about 3 year. Last week one of th guys did some messing around trying to install some SSL certificates, adding IP addresses, etc.
Since then, we cannot authenticate to the webservice from the local machine – ie:

We have a webservice on server1 in a website using host headers. If we try to call the
webservice from another site on this server in asp.net code (passing valid  credentials) it gives us a 401 error. If we try to access the webservice from server 2 using the same credentials it lets us in. It just cannot seem to authenticate on server 1 when called from server 1.

We setup the webservice on server2 with the exact same settings. If we call the webservice that is on server 2 form server 2 it works. If we call the webservices that is on server2 from server 1 that also works.

Server1->server1 – does not work – 401 error
Server1->server 2 works
Server2->server1 – works
Server2->server2 – works

The credentials being passed are the same for all calls. The credentials are the default credentials from the credential store. If we test to ensure we have a valid user, we do in all cases. We have also tried explicitly passing a username, password and domain as a new set of credentials witht eh exact same results (it works for all bar server1->server1).
Any ideas?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
The calling code using default credentials
Dim ws As New filesdev.WebService
        Try
            ws.PreAuthenticate = True
            ws.Credentials = System.Net.CredentialCache.DefaultCredentials
            MessageBox.Show(ws.HelloWorld)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

Author

Commented:
or explicit credentials
Dim ws As New filesdev.WebService
        Try
            Dim cache As System.Net.CredentialCache = New System.Net.CredentialCache()
            cache.Add(New Uri(ws.Url), "Negotiate", New System.Net.NetworkCredential("username", "password", "ourdomain"))
            ws.Credentials = cache

            ws.PreAuthenticate = True
            ws.Credentials = cache
            MessageBox.Show(ws.HelloWorld)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Open in new window

Author

Commented:
further to the above - we are using host headers for the site hosting the webservice. if we nmap localhost tothe site and call the webservice using localhost it all works properly. If we call it using the hostheader it still gives us 401 error.
fixed it by adding a loopback key to the registry

http://chillicode.wordpress.com/tag/custom-host-header/

Author

Commented:
no other answers, plus fixed it mysefl

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial