0
Я создаю приложение интрасети MVC в ASP.NET C# с аутентификацией Windows, и мне нужно запустить внешний скрипт powershell с учетными данными пользователей.Запуск powershell в качестве зарегистрированных пользователей Windows в ASP.Net intranet
Я добавляю в свой файл 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();
Но я всегда IIS пользователя в PowerShell
User Powershell : iis apppool\www.site.com > user C# : DOMAIN\alopez User Authentifier : DOMAIN\alopez type System.Security.Principal.WindowsIdentity
Вы создаете объект powershell ('PSRunner?') Под WindowsImpersonationContext? –
Да, я создал объект: PSRunner.ExecuteScript(), чтобы запустить команду powershell и прочитать и вернуть результат. – Alban