[英]Access denied when using powershell on IIS webserver
我的 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。
我曾尝试使用 impersonator 类,但这也不起作用。
这是我的一些代码。
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"/>
在 IIS 中,我将 ApplicationPoolIdentity 更改为 LocalService。 这解决了运行已发布的 Visual Studio 网站时访问被拒绝错误,但它在发布前运行良好。
这可能是一个“双跳”身份/安全问题。
在 localhost 上运行时,Windows 身份在同一台机器上是已知的。
在 Web 服务器上运行时,至少还涉及一台机器。
相关问题包括: IIS 使用什么身份来运行网页? 该 ID 是否有权使用网络? 该 ID 是否有权在远程服务器上执行密码重置?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.