C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




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


Posted Date: 12 Sep 2006    Resource Type: Articles    Category: WCF/Webservices
Author: Harish RanganathanMember Level: Gold    
Rating: Points: 10



Introduction


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.

Why this Error?


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.

Resolution


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.

Summary


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





Responses

Author: Rajaraman    16 Dec 2006Member Level: Diamond   Points : 0
Good Articles..


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ASP.NET Webservices - Invoking Webmethods from Remote Machine
Previous Resource: What's new in .NET 2.0?
Return to Discussion Resource Index
Post New Resource
Category: WCF/Webservices


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use