The request failed with HTTP status 401: Access Denied

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值