2012-05-25 48 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

相關問題