简体   繁体   English

ASP.Net Core 2-Powershell远程处理仅在IIS Express中有效(Kestrel无法正常工作)

[英]ASP.Net core 2 - powershell remoting works only in IIS Express (Kestrel not working)

I'm trying to connect powershell session from my ASP.Net Core 2 app (.NET Framework 4.6.2 as a platform) to my Exchange server. 我正在尝试将Powershell会话从ASP.Net Core 2应用程序(以.NET Framework 4.6.2作为平台)连接到Exchange服务器。 Code works perfectly when using IIS Express (debug in Visual studio), but I had no luck using Kestrel. 使用IIS Express(Visual Studio中的调试)时,代码可以完美工作,但是使用Kestrel却没有运气。

Exchange is set up corretly. 交易所设置正确。 I can successfully connect using powershell or using following code with IIS Express. 我可以使用Powershell或IIS Express使用以下代码成功连接。

Create powershell connection: 创建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();

Error: 错误:

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()

There was a problem on Exchange side. Exchange方面存在问题。 WinRM HTTPS listener was missing. WinRM HTTPS侦听器丢失。 You can check listeners with command winrm e winrm/config/listener . 您可以使用winrm e winrm/config/listener命令检查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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 设置DBContext时出现ASP.NET Core 2.2错误(在Kestrel中起作用,不在IIS Express中起作用) - ASP.NET Core 2.2 error when setting up DBContext (works in Kestrel, not in IIS Express) ASP.Net Core Web API 适用于 IIS Express,但在部署到 IIS 时不起作用 - ASP.Net Core Web API works on IIS Express, but not working when deployed to IIS ASP.NET Core、Kestrel和IIS之间有什么关系? - Whats the relationship between ASP.NET Core, Kestrel and IIS? ASP.NET Core Routing适用于VS IIS Express,但不适用于IIS 10 - ASP.NET Core Routing works in VS IIS Express but not in IIS 10 在 Windows 身份验证的 ASP.Net 5 中使用 IIS Express/Kestrel 时,User.IsInRole 始终为 false - User.IsInRole is always false when using IIS Express / Kestrel in ASP.Net 5 with Windows Authentication Kestrel on https with asp.net core 1.0 - Kestrel on https with asp.net core 1.0 记录asp.net core / kestrel中的异常 - Logging exceptions in asp.net core / kestrel 使用没有ASP.NET核心的Kestrel - Using Kestrel without ASP.NET core Asp.Net Core 应用程序使用 Kestrel web 服务器而不是 IIS,为什么? - Asp.Net Core application using the Kestrel web server instead of IIS, why? 仅当使用IIS Express执行时,Asp.Net Core项目才提供“未找到网页” - Asp.Net Core project gives “No webpage was found” only when executed with IIS Express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM