2012-05-25 46 views
1

我有一个用于我的0ffice 365用户的密码重置网站。它在后台运行powershell命令来重置用户密码。出于某种原因,当我使用VS并且我使用该页面运行浏览器时,它工作正常。但是,当我从现场运行它时,我得到这个错误在IIS网络服务器上使用powershell时访问被拒绝

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"/> 

回答

1

这可能是一个“双跳”身份/安全问题。

在本地主机上运行时,Windows身份在同一台计算机上已知。
在Web服务器上运行时,至少还有一台机器参与其中。

相关问题包括:IIS使用什么身份运行网页?该ID是否有权使用网络?该ID是否有权在远程服务器上执行密码重设?

+0

在我的网络配置我有身份impersonate = true,我不确定它使用什么身份,但没有设置。我在哪里可以检查? – user541597

相关问题