简体   繁体   中英

"HTTP status 401: Access Denied" error for web service even when the virtual directory allows Anonymous access

i have a web service hosted on another server with the Anonymous Access CheckBox in IIS is already checked. when my local web application is trying to access the web service, i still get the "The request failed with HTTP status 401: Access Denied." error. my web application is calling the web service like the following:

MyObject.WebService ws = new MyObject.WebService (); ws.Retrieve(someParams);

what am i missing here?

Here is a good reference on diagnosing 401 errors.

From that, one place to start is looking at the credentials you configure for the anonymous user. If they are incorrect (if perhaps the user password was changed elsewhere) you will get an HTTP 401.

Make sure your directory permissions are also set to allow everyone read access. A lot of times doing local dev work I will forgot that the directory being accessed has a seperate set of permissions that need to be altered.

Cheers!

Check this http://www.c-sharpcorner.com/UploadFile/mahesh/40107282006095201AM/401.aspx .

//Assigning DefaultCredentials to the Credentials property //of the Web service client proxy (myProxy). myProxy.Credentials= System.Net.CredentialCache.DefaultCredentials;

This code worked for me.

have you try un selecting the allow iis to control password some times that get out of sink.

try the site and it may work. you sould be able to reenable control after that

Try the following (note the PreAuthenticate thingy):

MyObject.WebService ws = new MyObject.WebService(); 
ws.PreAuthenticate = true;
response = ws.Retrieve(someParams);

For more detailed explanation why this may work you can reference following answer here http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/3ae9753d-2d97-45b9-9ba2-6d551fe60a48/ .

I think what might be happening is that you are getting a 401 - permission denied but as to whom the permission is denied to is unclear. I am guessing at this point you have checked the NTFS permissions on the machine, and have confirmed that you do have access.

Next I would look at what account the application pool uses. If it is the default setup, it will probably be the NT Network Service Account. If that is the case, confirm that the account does have access to the application directory. If that is also the case it might perhaps be a COM+ security setting. By default your network service account does not have permission to remotely launch components. If this is the case you will be seeing errors in the system and security log that will say things link, "Unable to launch component "

Looking at the IIS log files and the system and security event logs on the iis server often yield more clues.

Hope it helps Best Regards Rihan Meij

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM