我已经在 MVC3 (C#) 中创建了我自己的自定义 IIS 目录浏览器并且遇到了困难。
目前我正在使用Microsoft.Web.Administration
命名空间来获取工作正常的虚拟目录,但是我想我会尝试使用 PowerShell,因为 Site 类需要对 windows 目录中的文件夹的权限。
目前我的代码如下:
PowerShell ps = PowerShell.Create();
ps.AddCommand("import-module");
ps.AddArgument("webadministration");
ps.AddCommand("get-webvirtualdirectory");
ps.AddParameter("Name", "Default");
IEnumerable<PSObject> results = ps.Invoke();
现在默认确实有两个虚拟目录,但是当我运行这段代码时没有发生错误,一切似乎都按预期工作但是,“结果”中返回的集合是空的..
更令人困惑的是,当我直接调用powershellimport-module webadministration
时get-webvirtualdirectory -name Default
,它会按预期工作,返回两个列表。