我为 0ffice 365 用户的 0ffice 365 用户有一个密码重设网站。 它在背景中运行电壳命令, 以重置用户密码。 出于某种原因, 当我使用 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.
该页面是aspx.net, 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"/>