0ffice365ユーザー用のパスワードリセットWebサイトがあります。バックグラウンドで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.
ページはaspx.netで、C#コードが背後にあります。
なりすましクラスを使用してみましたが、それも機能しません。
これが私のコードの一部です。
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"/>