ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

You may receive the error "The request failed with HTTP status 401: Access Denied." when trying to access a Webservice from your ASP.NET Application.

This normally indicates that Anonymous access has been disabled for the Webservice.

Also, when you try to step into the webservice using the Visual Studio debugger, "Unable to automatically step into the server. The remote procedure could not be debugged. This usually indicates that debugging has not been enabled on the server. See help for more information"
in this scenario.

We can resolve this issue by either of the following ways:

1. Enabling Anonymous Access in the IIS Directory Security

To do this, the following steps will help you.

1. Click "Start" - "Run" - Type "inetmgr" and press "Ok" or "Enter" Key

2. IIS Control panel opens.

3. Expand the appropriate nodes and navigate to the virtual directory of your Web Service Application.

4. Select the Virtual directory, Right Click and select "Properties"

5. Switch to the "Directory Security" Tab and then Click "Edit".

6. Check the "Anonymous Access" CheckBox.

7. Click "Ok" twice to exit.

This should solve the issue.

2. Programattically assigning the Credential Cache

In case you dont have access to change the IIS Settings or you just dont want to allow anonymous because other applications are using it, then you can programatically provide the permissions by specifying the credential cache.

Let us assume we have a Webservice, Service which has the default Web Method HelloWorld. Let us see the steps involved in accessing the service.

Service Service1 = new Service();
Service1.PreAuthenticate = true;
Service1.Credentials = System.Net.CredentialCache.DefaultCredentials;
Response.Write(Service1.HelloWorld());


As you can see, we are passing the CredentialCache object for the Service1.

This would ensure that we preauthenticate the access to the Service. This would be applicable in the case of Integrated Windows Authentication scenarios.

Cheers and Happy Programming !!!

posted @ Tuesday, February 21, 2006 3:14 AM

Print

Comments on this entry:

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by RonCola at 7/19/2006 7:11 PM
Gravatar
do as in number 1. and if it still does not work, set the User to ASPNET and password to nothing...worked for me

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Tony at 11/8/2006 1:11 AM
Gravatar
I have a simular problem and would like some feedback.

Regards,
Tony

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by SonNguyen at 11/25/2006 1:21 AM
Gravatar
Thanks very much, I work with me !

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Nimish v. Goray at 12/12/2006 2:32 AM
Gravatar
Thanks a lot. The article was definitely helpful.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by vijay makam at 12/13/2006 1:27 PM
Gravatar
Thanks a lot!!
it did work 4 me...

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Vijay at 1/30/2007 4:07 AM
Gravatar
Thanks for the help. Solve my problem.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Sudha at 1/30/2007 7:52 AM
Gravatar
I get the error even after i do all this. The webservice is deployed in a different server.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Muhammad Rashid at 2/8/2007 12:44 PM
Gravatar
I get the error even after i do all this.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Sachin at 2/26/2007 7:55 AM
Gravatar
I get error when I am trying to access the webservice from another client machine

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Anish Kumar at 3/8/2007 5:54 AM
Gravatar
Hi Friends,

I am also felt this same problem and now its working fine. The Solution is

1. Click Start - Choose Run - Type "Inetmgr" and press Enter Key.
2. The IIS Control Panel window opens.
3. Select your virtual directory and right click - select "Properties"
4. Click the "Directory Security" tab and and click "Edit" Button.
5. Check the "Anonymous Access" Check box is enable or not.
6. If it is not enable click the check box and also click "Edit Button"
in that form.
7. Check the "Allow IIS to control Password" checkbox is enable or
not.
8. If it is also not enable click the check box.
9. Press "OK" button twice to exit.

This problem should be solve...

Regards,
Anish

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Raghu at 3/9/2007 4:31 PM
Gravatar
I had this issue, googled and your thread is toppest. The second solution is perfect for me..

Thanks,
Raghu

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by re at 8/9/2007 5:01 PM
Gravatar
Last solution works

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by armagan at 8/12/2007 6:11 PM
Gravatar
thank you for your solution

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by prashant at 11/1/2007 8:07 PM
Gravatar
Thanks a lot for this querry

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Kateki Gupta, New Delhi at 1/15/2008 9:40 PM
Gravatar
If the above solutions don't work,try the following steps:

To do this, the following steps will help you.

1. Click "Start" - "Run" - Type "inetmgr" and press "Ok" or "Enter" Key

2. IIS Control panel opens.

3. Expand the appropriate nodes and navigate to the virtual directory of your Web Service Application.

4. Select the Virtual directory, Right Click and select "Properties"

5. Switch to the "Directory Security" Tab and then Click "Edit".

6.Try Checking the integrated windows authentication checkbox.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Abhi at 3/10/2008 8:41 PM
Gravatar
if it does not solve ,
add this code to the proxy Credentials

oApp.Credentials = System.Net.CredentialCache.DefaultCredentials

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Gokulsankar at 3/11/2008 2:22 AM
Gravatar
it is very useful for me.thanks for ur help

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Ashok at 3/16/2008 6:27 PM
Gravatar
Both the solutions works fine.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by jones1977 at 3/24/2008 5:47 AM
Gravatar
Both worked for me :).
Thanks for the solution.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Tulika Gupta at 3/25/2008 8:42 PM
Gravatar
Thanks for the solution. First option itself solved my problem. :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by deepa at 6/4/2008 6:55 PM
Gravatar
hi what r the steps for second solution, bcoz i havn't the permission to access the IIS.
plz anyone help to solve using second solution

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Luis at 6/11/2008 3:24 AM
Gravatar
Yes, that works

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Carla at 7/7/2008 3:05 AM
Gravatar
Thanks, the first option doesn't work in some servers. The second option solved my problem.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Vaibhav Gaikwad at 7/7/2008 4:22 PM
Gravatar
Hi,
I do not create the proxy classes using the WSDL and VS IDE, I create all of them on fly. And then I try invoking the web-method using Reflection.
// ClassObj = dynamically compiled class from web-ref.
// This works in case i keep anonymous access ON, but I don't want to do that.
object objResult = objMethodInfo.Invoke(ClassObj, args);

Can you tell me how to aviod 401 in this case, or to pass credentials in my case?

Regards,
Vaibhav

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Vaibhav Gaikwad at 7/7/2008 4:33 PM
Gravatar
Hi again,
Pls. don't spare time on my issue.
I found the solution by casting my object type to SoapHttpClientProtocol type, and then setting its credentials property.

Thanks
Vaibhav

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Cibi Jacob at 7/8/2008 2:26 AM
Gravatar
Hi
I am new to asp.net. I am creating an intranet application which needs the windows loginname. I have unchecked the Anonymous login in inetmgr and in web.config, identity impersonate="true". I got the login name from System.Security.Principal.WindowsIdentity.GetCurrent.Name. It worked fine in my localhost machine. But the problem is that when I am trying to access the site from another machine, it requests for windows login. Then I checked the Anonymous login in inetmgr. At that time the login was not there but the windows login user name is not getting properly. It is showing the anonymous access's username. How can I solve this problem? How can I get the windows login username while accessing the site from another machine?

Please help me..

Thanks in advance.
Cibi Jacob

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Rits at 7/22/2008 9:33 AM
Gravatar
good job...it works for me

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by anyoneis at 8/1/2008 6:51 AM
Gravatar
Spot on! Especially the part that lets us step into and debug web services when anonymous access is turned off. Thanks a bazillion.

David

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Prachi at 8/19/2008 11:57 PM
Gravatar
good solution

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Uday at 8/20/2008 1:07 AM
Gravatar
Hi,
I have applied all the setting sspecified here, But nothing works for me. I have a webservice and an ASP.Net web Application in my local pc. When i try to open the web service in browser, it is working fie. But when i try to call it from ASP.Net Application it is throwing error "The request failed with HTTP status 401: Access Denied". I have admin rights in my system and i have checked the anonimous access check box for the application as well as service. I have the Integrated Windows Authentication check box on. I dont know why i am keep on getting the same error. Even i changed the user name to ASPNET and set the leave the password column as empty. Please help me.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by rüya tabiri at 8/29/2008 2:36 AM
Gravatar
thank youuu

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Adrian castañeda at 9/1/2008 1:45 AM
Gravatar
i need validate my webservice client with the webservice server but the server have the next:
1.-anonymous access is disabled
2.-Basic authentication(password is sent in clear text) ACTIVATED

what i do i need help thank you

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Anup at 9/4/2008 9:58 PM
Gravatar
Thanks a lot. You are such a life saver :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Aravinda at 9/11/2008 7:57 AM
Gravatar
Thank you so much.
-Aravinda

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by biswajit at 9/23/2008 11:52 PM
Gravatar
above solution worked,thanks

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Reena at 9/24/2008 6:28 PM
Gravatar
Hi, I have installed my .net application on a Windows 2003 machine having sharepoint installed
Could Sharepoint be conflicting with the web service of the .net application?I am getting the same error
The request failed with HTTP status 401: Unauthorized.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by davood at 9/27/2008 10:24 PM
Gravatar
Very very good. It works for me

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Kris at 10/6/2008 7:51 PM
Gravatar
I have an asp.net website which consumes the web service via a class library project. I followed the above mentioned steps. Still I am getting the same error message. Please help me.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by rahu at 10/7/2008 10:34 AM
Gravatar
Hi,

I'm gettin general network error in application.
It is occuring sometimes in application and gets resolved automatically.

Please someone help me.

# General network error in asp.net application

Left by rahu at 10/7/2008 10:53 AM
Gravatar
Hi,

I'm gettin general network error in application.
It is occuring sometimes in application and gets resolved automatically.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by narges at 10/12/2008 1:50 PM
Gravatar
thanks you help me alot be succed

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Rain at 10/13/2008 1:33 PM
Gravatar
Very good! Great solution :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Joe at 11/22/2008 4:23 AM
Gravatar
Since the lat batch of windows updates on 11/17 I now get the same error. We roll back the patches and everything works. I use the process you described in step 2 to pass the credentials to my WS and it does not work. Anyone else have the same problem? BTW my app runs on a win2k server box and is asp.net 1.1.

Thanks in advance.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by SBL at 11/29/2008 5:24 PM
Gravatar
I have seen many sites before and most of them do not look this good.
Very helpful....
Regards,
SBL

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by ck at 12/29/2008 11:42 AM
Gravatar
Thanks :)))))))))

Great, clear answer

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by oscar at 1/26/2009 6:28 PM
Gravatar
Thx So Much ^^¡

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by TekNik at 2/6/2009 7:17 PM
Gravatar
Ok, I fought with this for 3 days, but finally got it. Set the directory security to ASPNet, allow IIS to control the password. Then go to the ASP.NET tab, click Edit Configuration and go to the Authentication tab. At the bottom check the Role Management Enabled and select ASPNetSQLProvider from the Role Provider Class. That fixed it for me.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by TribunMax at 2/10/2009 7:48 PM
Gravatar
In my case, I had to give proper permissions to the Internet Guest Account. In IIS Manager right click on the web service node, click on "Permissions" and add the Internet Guest Account. Hope that helps anybody.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Phi at 2/25/2009 8:26 AM
Gravatar
thanks alot , it work with me .

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Sarvesh at 3/21/2009 2:39 PM
Gravatar
thank u very much for ur clear explanation

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Pavel at 4/9/2009 6:17 PM
Gravatar
Thanks for the help. Solve my problem.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by irfan saputra at 4/14/2009 1:04 PM
Gravatar
thanx a lot...

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Suresh at 6/17/2009 5:10 AM
Gravatar
Thanks alot dude... :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by jesusldb at 7/1/2009 10:00 AM
Gravatar
excelent! the second solution work for me! :)

thanks

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by web tasarımı at 7/27/2009 5:13 PM
Gravatar
Thanks for the help. Solve my problem.
excelent! the second solution work for me! :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by S.Arunkumar at 7/30/2009 12:47 AM
Gravatar
Thanks a lot. Solved my issue by method #2.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Hira at 8/4/2009 1:31 AM
Gravatar
Thanks. 2nd one worked for me.great.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Manny at 8/10/2009 11:20 PM
Gravatar
I have tried every solution you guys provided without much luck.

I am trying to access Project Server 2007 services using PSI. Added web reference, set Credentials to DefaultCredentials and followed the above stated steps. Yet, I keep getting the 401 Unauthorized error.

Please HELP !!!

# ASP.NET Webservices: "The request failed with HTTP status 401: Unauthorized." Error

Left by Dom at 8/21/2009 3:50 AM
Gravatar
Hi,

I'm getting the same error as above, but I have anonymous access enabled. The web service I'm trying to access is located on a different server to the web application that's calling it.

I've installed the web service on the same machine as the web app, and it runs fine. But as soon as I alter the web app to call the web service on a different server, I get the 'unauthorized' error message.

Are there any permissions/settings that I need to check? Any other ideas?

Thanks a lot! :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by rana omair at 8/27/2009 2:36 AM
Gravatar
Thanks a lot! :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by mamun at 9/14/2009 7:23 PM
Gravatar
Thanks, its solve my problem.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Programmer at 9/16/2009 3:35 AM
Gravatar
The second solution worked for me perfeectly!!

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Niks at 9/21/2009 11:06 PM
Gravatar
I tried ASPNET user and it worked for me...

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Priyanka at 9/24/2009 5:46 PM
Gravatar
Thanks a lot !! The second solution worked like a charm :)

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Marimuthu.R at 9/30/2009 12:07 AM
Gravatar
Hi all,
I tried each and every of the option listed above but still am not able to solve the problem. Am not able to hit any web services from my application. Plz some one let me know the reason for it.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Web developer at 10/1/2009 3:35 AM
Gravatar
Hey, that was interesting, the aspnet user most deffinately worked for me! Fantastic.



Anyway, thanks for the post

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Ritesh at 10/8/2009 7:25 PM
Gravatar
After tring, Service Service1 = new Service();
Service1.PreAuthenticate = true;
Service1.Credentials = System.Net.CredentialCache.DefaultCredentials;

I get {"Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."}.

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by Shiva at 10/14/2009 11:43 PM
Gravatar
I am calling an secure java web service from asp.net client , I am sending the user name and pwd from code

Protected Overrides Function GetWebRequest(ByVal uri As System.Uri) As System.Net.WebRequest
Dim webRqest As System.Net.WebRequest
Dim crd As System.Net.ICredentials
Dim netCredential As System.Net.NetworkCredential


webRqest = MyBase.GetWebRequest(uri)
netCredential = New System.Net.NetworkCredential("AxisUser", "AxisPassword")
crd = netCredential.GetCredential(uri, "Basic")
webRqest.Credentials = crd
webRqest.PreAuthenticate = True
GetWebRequest = webRqest

End Function

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by M Sri at 10/15/2009 6:14 PM
Gravatar
Ya this aritcle is very much helpfull for all beginners

thanks guys

# Mr

Left by Raj at 10/19/2009 11:45 PM
Gravatar
hi

thanks for the listing the steps to solve the problem easily

# re: ASP.NET Webservices: "The request failed with HTTP status 401: Access Denied." Error

Left by vinarja at 11/24/2009 1:54 AM
Gravatar
hi, thanks a lot...i spent nearly 3 days to get it done..finally the adding of aspnet user and providing permissions worked, hurrah!!!

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345