【问题标题】:ASP.Net core 2 - powershell remoting works only in IIS Express (Kestrel not working)ASP.Net core 2 - powershell 远程处理仅在 IIS Express 中有效(Kestrel 不工作)
【发布时间】:2019-07-25 08:25:40
【问题描述】:

我正在尝试将 powershell 会话从我的 ASP.Net Core 2 应用程序(.NET Framework 4.6.2 作为平台)连接到我的 Exchange 服务器。代码在使用 IIS Express(在 Visual Studio 中调试)时运行良好,但我在使用 Kestrel 时运气不佳。

Exchange 设置正确。我可以使用 powershell 或使用以下代码与 IIS Express 成功连接。

创建 powershell 连接:

var psOptions = new PSSessionOption()
{
    SkipCACheck = true,
    SkipCNCheck = true,
    SkipRevocationCheck = true
};
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://" + _server + "/powershell?serializationLevel=Full"),
    "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credentials);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
connectionInfo.SetSessionOptions(psOptions);
_runspace = RunspaceFactory.CreateRunspace(connectionInfo);

_runspace.Open();

错误:

Hosting environment: Production
Content root path: path
Now listening on: http://127.0.0.1:12006
Application started. Press Ctrl+C to shut down.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLOGQUBGFLJ1", Request id "0HLOGQUBGFLJ1:00000001": An unhandled exception was thrown by the application.
System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server hostname failed with the following error message : The WinRM client sent a request to an HTTP server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does not support the WS-Management protocol. For more information, see the about_Remote_Troubleshooting Help topic.
   at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()

【问题讨论】:

    标签: c# powershell asp.net-core kestrel-http-server


    【解决方案1】:

    Exchange 端出现问题。 WinRM HTTPS 侦听器丢失。您可以使用命令winrm e winrm/config/listener 来检查监听器。

    PS C:\WINDOWS\system32> winrm e winrm/config/listener
    Listener
        Address = *
        Transport = HTTP
        Port = 5985
        Hostname
        Enabled = true
        URLPrefix = wsman
        CertificateThumbprint
        ListeningOn = <hidden>
    
    
    
    Listener
        Address = *
        Transport = HTTPS
        Port = 5986
        Hostname = <hidden>
        Enabled = true
        URLPrefix = wsman
        CertificateThumbprint = <hidden>
        ListeningOn = <hidden>
    

    【讨论】:

      猜你喜欢
      • 2019-06-17
      • 1970-01-01
      • 2020-01-21
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多