The request failed with HTTP status 401: Unauthorized

Matt W picture Matt W · Jul 19, 2010 · Viewed 62.3k times · Source

I have a .NET 2.0 website (VB) running in my IIS6 (XP Pro SP2) and a .NET 3.5 (configured as .NET2 under IIS's ASP.NET tab, of course) hosting an ASMX web service.

In Chrome, I can call the ASMX and invoke the web methods successfully. However, in calling the web methods in code, from the .NET 2.0 website I get:

The request failed with HTTP status 401: Unauthorized.

How do I get around this?

Answer

btlog picture btlog · Jul 19, 2010

You need to set the credentials in you application when you initialise the webService object.

Something like webService.UseDefaultCredentials = true

This will set the credentials of the request to the current user executing the application.