C# 即使虚拟目录允许匿名访问,Web 服务也会出现“HTTP 状态 401:拒绝访问”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/241971/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:29:24  来源:igfitidea点击:

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

c#.netasp.netweb-servicesiis

提问by Gnot

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:

我在另一台服务器上托管了一个 Web 服务,IIS 中的匿名访问复选框已经被选中。当我的本地 Web 应用程序尝试访问 Web 服务时,我仍然收到“请求失败,HTTP 状态为 401:拒绝访问”。错误。我的 Web 应用程序正在调用 Web 服务,如下所示:

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

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

what am i missing here?

我在这里错过了什么?

回答by B.A.Hammer

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

你有没有尝试过选择允许 iis 控制密码有时会退出接收器。

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

尝试该网站,它可能会工作。在那之后你应该能够重新启用控制

回答by David Hall

Hereis a good reference on diagnosing 401 errors.

是诊断 401 错误的很好参考。

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.

从那里开始,一个地方是查看您为匿名用户配置的凭据。如果它们不正确(如果用户密码可能在其他地方被更改),您将收到 HTTP 401。

回答by thismat

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!

干杯!

回答by Vlad N

Try the following (note the PreAuthenticate thingy):

尝试以下操作(注意 PreAuthenticate ):

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/.

有关为什么这可能起作用的更详细解释,您可以在此处参考以下答案http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/3ae9753d-2d97-45b9-9ba2-6d551fe60a48/

回答by Rihan Meij

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.

我认为可能发生的情况是您收到了 401 - 权限被拒绝,但权限被拒绝的对象尚不清楚。我猜此时您已经检查了机器上的 NTFS 权限,并确认您确实有权访问。

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 "

接下来,我将查看应用程序池使用的帐户。如果是默认设置,则可能是 NT 网络服务帐户。如果是这种情况,请确认该帐户确实有权访问应用程序目录。如果情况也是如此,则可能是 COM+ 安全设置。默认情况下,您的网络服务帐户无权远程启动组件。如果是这种情况,您将在系统和安全日志中看到错误,显示链接“无法启动组件”

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

查看 IIS 日志文件以及 iis 服务器上的系统和安全事件日志通常会产生更多线索。

Hope it helps Best Regards Rihan Meij

希望它有助于最好的问候 Rihan Meij

回答by Anish V

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

检查这个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;

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

This code worked for me.

这段代码对我有用。