我在 Intranet 上有一个 MVC Web 应用程序,并且希望能够在我们的 FTP 服务器上创建文件以发送给外部合作伙伴。
模拟代码使用 WindowsImpersonationContext。
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();
StreamWriter sw = System.IO.File.CreateText("PathOnFTPServer");
sw.Write("data");
impersonationContext.Undo();
这是正在发生的事情以及我提出问题的原因:
模拟前
User.Identity.Name:[我的 Windows 凭据]
System.Security.Principal.WindowsIdentity.GetCurrent().Name: NT AUTHORITY\NETWORK SERVICE
冒名顶替
User.Identity:[我的 Windows 凭据]
GetCurrent.Name:[我的 Windows 凭据]
模拟撤消
User.Identity:[我的 Windows 凭据]
GetCurrent.Name:NT AUTHORITY\NETWORK SERVICE
因此,在我模拟之前,当前用户是系统帐户,但在模拟之后,它使用的是我的 Windows 域帐户,该帐户有权在 FTP 服务器上创建文本文件。该代码使用 Visual Studio Web 服务器在本地工作,但当我将其部署在我们的测试服务器上的 IIS 上时却不能。
我收到拒绝访问错误。当模拟正确的用户时,错误的原因是什么?