繁体   English   中英

在ASP.net Intranet中以登录的Windows用户身份运行Powershell

[英]Run powershell as logged windows user in ASP.net intranet

我正在使用Windows身份验证在ASP.NET C#中创建MVC内部网应用程序,并且需要使用用户凭据运行外部powershell脚本。

我添加了我的web.config文件。

<system.web>
    <authentication mode="Windows" />
    <identity impersonate="true"/>
</system.web>
<runtime>
    <!--http://blogs.msdn.com/b/powershell/archive/2007/09/10/impersonation-and-hosting-powershell.aspx-->
    <legacyImpersonationPolicy enabled="false"/>
    <alwaysFlowImpersonationPolicy enabled="true"/>
</runtime>

在我的控制器中

        // http://support.microsoft.com/kb/306158
        System.Security.Principal.WindowsImpersonationContext impersonationContext;
        impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

        ViewBag.Message = "User Powershell : " + PSRunner.ExecuteScript("Whoami;") + "   > user C# : " + System.Security.Principal.WindowsIdentity.GetCurrent().Name + "    User Authentifier : " + User.Identity.Name + " type " + User.Identity.GetType();

        impersonationContext.Undo();

但是我总是在Powershell中有IIS用户

User Powershell : iis apppool\www.site.com > user C# : DOMAIN\alopez User Authentifier : DOMAIN\alopez type System.Security.Principal.WindowsIdentity

我不知道PSRunner如何初始化Powershell运行时,但是如何以其他用户身份启动Powershell进程呢: Runas

暂无
暂无

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

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