Problem :
I am very new to ASP.Net. I have created my first ASP.Net application which impersonates the user in order to create the AD group, and after that it launches the powershell process as the user saperately.
But because of some reason the group creation works fine and shows as success in the Event Viewer, and when it tries to run my PowerShell script, I face the following error:
The user has not been granted the requested logon type at this machine.
The below is my code which is failing:
SecureString securePassword = new SecureString();
foreach (char c in model.AdminPassword)
{
securePassword.AppendChar(c);
}
PSCredential psCredential = new PSCredential("CONTOSO\\" + User.Identity.Name, securePassword);
ProcessStartMyinfo myinfo = new ProcessStartMyinfo("c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", "c:\\PowershellScripts\\EnableDL.ps1 -dlName '" + model.Name + "'");
myinfo.UseShellExecute = false;
myinfo.RedirectStandardOutput = true;
myinfo.RedirectStandardError = true;
myinfo.RedirectStandardInput = true;
myinfo.CreateNoWindow = true;
myinfo.Domain = "CONTOSO.COM";
myinfo.UserName = User.Identity.Name;
myinfo.Password = securePassword;
Is there any way to remove this error? I would rather not compromise with the security policy with the server ideally, and this application will be used by around 100+ users.