小编Jas*_*emp的帖子

ASP.NET MVC中的模拟

我在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();
Run Code Online (Sandbox Code Playgroud)

这是发生了什么以及我的问题的原因:

预先假冒

User.Identity.Name:[我的Windows凭据]

System.Security.Principal.WindowsIdentity.GetCurrent().名称:NT AUTHORITY\NETWORK SERVICE

发布模仿

User.Identity:[我的Windows凭据]

GetCurrent.Name:[我的窗口凭据]

模仿撤消

User.Identity:[我的Windows凭据]

GetCurrent.Name:NT AUTHORITY\NETWORK SERVICE

因此,在我冒充之前,当前用户是系统帐户,但在模仿之后,它正在使用我的Windows域帐户,该帐户有权在FTP服务器上创建文本文件.该代码使用visual studio Web服务器在本地工作,但在我在测试服务器上的IIS上部署时则不行.

我收到拒绝访问错误.正确的用户被模拟时出现错误的原因是什么?

c# asp.net-mvc impersonation

23
推荐指数
1
解决办法
3万
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

impersonation ×1