我们开发了一个新的基于 Web 的应用程序,它通过 C# 调用 Citrix Xenapp Powershell cmdlet。Web 应用程序托管在 Citrix 服务器(这已经在场中)本身上,我们认为它足以访问 Citrix 场中的所有服务器。代码从 Visual Studio IDE 运行时会给出输出。但是,当我在 IIS 上创建一个虚拟目录并通过浏览器访问它时。
在 System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(对象输入,哈希表错误结果,布尔枚举)在 System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() 在 System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
以下是代码
protected void Page_Load(object sender, EventArgs e)
{
string usrname = "";
string svrname = "";
string appname = "";
string clntnme = "";
string clntip="";
string farm = "";
Runspace rsp = RunspaceFactory.CreateRunspace();
//rsp.ApartmentState = System.Threading.ApartmentState.STA;
//rsp.ThreadOptions = PSThreadOptions.UseCurrentThread;
rsp.Open();
PSSnapInException exp;
rsp.RunspaceConfiguration.AddPSSnapIn("Citrix.XenApp.Commands", out exp);
try
{
PowerShell ps3 = PowerShell.Create().AddCommand("Get-XAFarm");
ps3.Runspace = rsp;
foreach (PSObject pss in ps3.Invoke())
{
farm = pss.Properties["FarmName"].Value.ToString();
}
Response.Write("<DIV align=" + "center" + " style=" + "width:100%;height:100%" + ">" + farm + "<TABLE style=" + "width:100%" + ">");
Response.Write("<TR><TH>User</TH><TH>Server</TH><TH>Application</TH><TH>Address</TH><TH>Client Name</TH></TR>");
PowerShell sessions = PowerShell.Create().AddCommand("Get-XASession").AddParameter("Full").AddCommand("where-object").AddParameter("FilterScript", ScriptBlock.Create("{$_.BrowserName -ne $null }"));
sessions.Runspace = rsp;
foreach (PSObject psr in sessions.Invoke())
{
//IPAddress.Parse(psr.Properties["ClientAddress"].Value.ToString());
usrname = psr.Properties["AccountName"].Value.ToString();
svrname = psr.Properties["ServerName"].Value.ToString();
appname = psr.Properties["BrowserName"].Value.ToString();
clntnme = psr.Properties["ClientName"].Value.ToString();
//if (psr.Properties["ClientAddress"].Value != null)
//{
clntip = psr.Properties["ClientAddress"].Value.ToString();
//}
//clntip = psr.Properties["ClientIPV4"].Value.ToString();
Response.Write("<TR><TD>" + usrname + "</TD><TD>" + svrname + "</TD><TD>" + appname + "</TD><TD>" + clntip + "</TD><TD>" + clntnme + "</TD></TR>");
}
Response.Write("</TABLE>");
}
catch (Exception ex)
{
Response.Write(ex.StackTrace.ToString());
}
finally
{
rsp.Close();
}
}**
请让我知道是否必须在 IIS 上进行任何更改以使我能够aspx
成功访问该页面。