简体   繁体   English

ASP.NET MVC的模拟问题

[英]Impersonation issue with ASP.NET MVC

I'm having a strange problem while using impersonation with ASP.NET MVC. 在ASP.NET MVC中使用模拟时遇到一个奇怪的问题。 I have a site that checks the status of different servers by reading some configurations files on each one of them. 我有一个站点,通过读取每个服务器上的一些配置文件来检查不同服务器的状态。 The app can also modify such files. 该应用程序还可以修改此类文件。 Because the app will be used by several people (all of them with administrative grants in the servers),I need to have a log of all the changes done. 由于该应用程序将由几个人使用(所有人都在服务器中获得管理授权),因此我需要记录所有所做的更改。 I enabled Windows authentication to my site in IIS7 and also enabled id impersonation by adding the following to my web.config file. 我在IIS7中对我的站点启用了Windows身份验证,并且通过将以下内容添加到我的web.config文件中来启用了ID模拟。

<identity impersonate="true"/>

Just to be sure that the impersonation is working correctly, every time a user logged in I use the following to obtain the user that will be sending all the requests. 为了确保模拟工作正常,每次用户登录时,我都会使用以下命令获取将发送所有请求的用户。

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

When I enter the site from my Visual Studio environment, everything works correctly, the user logged is my NT id rather than the NETWORK SERVICE user and I'm able to access the remote files without problems. 当我从Visual Studio环境进入站点时,一切正常,登录的用户是我的NT ID,而不是NETWORK SERVICE用户,并且我能够毫无问题地访问远程文件。 However, when I publish the site to our server it stops working. 但是,当我将站点发布到我们的服务器时,它将停止工作。 Even though it does seem that the impersonation is working because the NT id of the logged user is shown as the windows identity, I cannot access the files. 即使由于登录用户的NT ID显示为Windows身份,模拟似乎也可以正常工作,但我无法访问这些文件。 What I found even weirder is that if I access the site directly on the server's browser, everything works ok, so I'm not sure where's the problem. 我发现甚至更奇怪的是,如果我直接在服务器的浏览器上访问该站点,则一切正常,因此我不确定问题出在哪里。 In resume, here's what I'm dealing with. 在简历中,这就是我要处理的内容。

  1. Id impersonation works from development environment 来自开发环境的ID模仿作品
  2. Id impersonation works browsing directly in the server where the site is. 身份模拟可直接在站点所在的服务器中浏览。
  3. Id impersonation doesn't work when accessing the site from a browser outside the server. 从服务器外部的浏览器访问网站时,无法使用ID模拟。 Even though the logged user name corresponds to the impersonated user profile, the site can not access the remote files. 即使登录的用户名对应于模拟的用户配置文件,该站点也无法访问远程文件。

Does anybody have an idea of what might be wrong? 有人知道什么地方可能出问题吗? I'm kind of lost with this one... 我有点迷失了这个...

In order to access remote files on behalf of an impersonated client, your server needs to be trusted for delegation. 为了代表模拟的客户端访问远程文件,需要信任您的服务器以进行委派。 See this KB article for more info, or just google "trusted for delegation". 有关更多信息,请参见此知识库文章 ,或者仅谷歌“受信任的委派”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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