c# - 模拟仅在指定用户时有效

标签 c# web-services model-view-controller web-config

我在没有指定用户的情况下使用模拟访问网络服务时遇到问题。

作品: <identity impersonate="true" userName="DOMAIN\USERNAME" password="MyPassword" / >

不起作用

<identity impersonate="true" /> 

在调试时,我使用下面的代码来验证是否使用了正确的域和用户名,它们是。

System.Security.Principal.WindowsIdentity.GetCurrent().Name;

这是我的更多 web.config

<authentication mode="Windows" />
<identity impersonate="true" /> 
<authorization>
  <allow users="*" />
  <deny users="?"/>
</authorization>

我正在登录提示,下图enter image description here

知道为什么只有当我在 web.config 中指定用户时它才会起作用吗?我正在使用相同的 Domain\Username 登录和我输入 <identity impersonate="true" userName="DOMAIN\USERNAME" password="MyPassword" / 的密码> 。我尝试过使用多个帐户,当我将他们的凭据放入 web.config 时,它们都可以正常工作但无法将身份设置为 <identity impersonate="true" />并登录。

编辑 远程服务器返回错误:(403) Forbidden。 enter image description here

编辑 2 调试时一切正常,同时在包含其托管的 IIS 的服务器上访问服务时,我尝试使用多个帐户,它们都可以正常工作。一切都在同一个域中

最佳答案

请注意来自 https://support.microsoft.com/en-us/kb/306158 的以下文本

Impersonate a Specific User for All the Requests of an ASP.NET Application

To impersonate a specific user for all the requests on all pages of an ASP.NET application, you can specify the userName and password attributes in the tag of the Web.config file for that application. For example: Note The identity of the process that impersonates a specific user on a thread must have the "Act as part of the operating system" privilege. By default, the Aspnet_wp.exe process runs under a computer account named ASPNET. However, this account does not have the required privileges to impersonate a specific user. You receive an error message if you try to impersonate a specific user. This information applies only to the .NET Framework 1.0. This privilege is not required for the .NET Framework 1.1.

To work around this problem, use one of the following methods: Grant the "Act as part of the operating system" privilege to the ASPNET account (the least privileged account).

Note Although you can use this method to work around the problem, Microsoft does not recommend this method. Change the account that the Aspnet_wp.exe process runs under to the System account in the configuration section of the Machine.config file.

您可以将 Aspnet_wp.exe 进程设置为以您试图模拟的用户身份运行以获得所需的权限。

这个之前也讨论过:How do you do Impersonation in .NET?

关于c# - 模拟仅在指定用户时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30105240/

相关文章:

c# - WPF 绑定(bind) TabControl TabItem

java - 使用大型 wsdl,我们可以修剪它吗?

java - 使用JAVA解析SOAP响应并提取特定节点

java - 无法使用 Spring-MVC 框架定位文件

java - 桌面(非网络)应用程序中的 MVC 框架

c# - 如何为我编写的类编写数组样式的初始化程序?

c# - 如何从单个解决方案生成多个 .exe 文件?

java - Java中使用HTTPS调用Web服务

java - 我正在寻找java web框架

c# - 使用 Image.Save 和 EncoderParameters 无损旋转 JPG 图像失败