我使用MVC web应用程序控制器通过以下代码连接exchange服务器powershell:
enter connectionInfo = new WSManConnectionInfo(new Uri(ConfigurationManager.AppSettings.Get ("WSManConnectionInfo").ToString()), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", newCred);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
string rspace = "space is OK";
try
{
//--create remote runspace
runspace = RunspaceFactory.CreateRunspace(connectionInfo);
} catch (Exception ex2)
{
rspace = ex2.Message.ToString();
}
ViewBag.rspace = rspace; //show the above error message on client side view上面的代码在我的本地机器上运行得很好,但是我在发布到生产服务器后得到了上面的错误,请注意我可以看到"Microsoft.Management.Infrustructure.dll“存在于生产服务器的bin文件夹中。
请告知如何修复此错误,非常感谢,
编辑:我甚至尝试添加这3行代码,但同样的错误;
connectionInfo.SkipCACheck =真;
connectionInfo.SkipCNCheck =真;
connectionInfo.MaximumConnectionRedirectionCount =4;此处代码
编辑: System.Management.Automation.dll也会添加到Reference文件夹中
发布于 2020-02-20 20:40:52
问题似乎已经解决了,我想这是由System.Management.Automation安装引起的,这就是我所做的:
1.首先确保在C:\windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll的References文件夹中添加了System.Management.Automation.dll,这个dll文件就在那里,但它仍然会导致错误。
2.转到管理Nuget包并从那里安装System.Management.Automation,虽然它们具有相同的名称,但我认为这个文件与第一步中添加的System.Management.Automation.dll不同。但是在安装这个文件之后,这个问题就解决了。C#代码没有任何变化,
https://stackoverflow.com/questions/60232380
复制相似问题