我有一个 0ffice 365 用户的密码重置网站。它在后台运行 powershell 命令来重置用户密码。出于某种原因,当我使用 VS 并使用页面运行浏览器时,它运行良好。但是,当我从实时站点运行它时,出现此错误
Processing data from remote server failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
该页面是带有 C# 代码的 aspx.net。
我曾尝试使用模仿者类,但这也不起作用。
这是我的一些代码。
using (new Impersonator("user", "domain", "pass"))
{
PSCredential creds = new PSCredential("office365email", "password");
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
new Uri("https://server.outlook.com/PowerShell-LiveID?PSVersion=2.0"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange", creds);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.ApartmentState = System.Threading.ApartmentState.STA;
runspace.ThreadOptions = PSThreadOptions.UseCurrentThread;
try
{
runspace.Open();
pipeline = runspace.CreatePipeline();
Command forwardcommand = new Command("Set-Mailbox");
forwardcommand.Parameters.Add("Identity", user);
forwardcommand.Parameters.Add("Password", pass);
pipeline.Commands.Add(forwardcommand);
try
{
pipeline.Invoke();
runspace.Close();
pipeline.Stop();
return "Password Successfully Changed";
}
catch (Exception er)
{
runspace.Close();
pipeline.Stop();
return er.Message;
}
}
catch (PSRemotingTransportException eer)
{
runspace.Close();
return eer.Message;// "Server busy please try again later";
}
}
有什么想法为什么我不能从实际网站上做到这一点,但我可以在我的本地主机上做到这一点?
<authentication mode="Windows"/>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
<providers>
<clear/>
<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
</providers>
</roleManager>
<identity impersonate="true"/>