简体   繁体   English

在MVC应用程序中使用Powershell从IIS获取虚拟目录

[英]Getting virtual directories from IIS with powershell in an MVC application

I have created my own custom IIS directory browser in MVC3 (C#) and have hit a rough spot. 我已经在MVC3(C#)中创建了自己的自定义IIS目录浏览器,并且遇到了麻烦。

Currently I am using the Microsoft.Web.Administration namespace to get virtual directories out which is working fine, however I thought I'd try with PowerShell as the Site class needs permission to a folder in the windows directory. 当前,我正在使用Microsoft.Web.Administration命名空间来获取运行良好的虚拟目录,但是我认为我将尝试使用PowerShell,因为Site类需要对Windows目录中的文件夹的权限。

Currently my code is as follows: 目前,我的代码如下:

        PowerShell ps = PowerShell.Create();
        ps.AddCommand("import-module");
        ps.AddArgument("webadministration");
        ps.AddCommand("get-webvirtualdirectory");
        ps.AddParameter("Name", "Default");
        IEnumerable<PSObject> results = ps.Invoke();

Now default does in have fact two virtual directories, however when I run this peice of code no errors occur, all seems to work as expected however, the collection returned in "results" comes out empty.. 现在默认情况下确实有两个虚拟目录,但是当我运行这段代码时,没有错误发生,所有操作似乎都按预期进行,但是,“结果”中返回的集合显示为空。

Even more of a conundrum, when I call import-module webadministration then get-webvirtualdirectory -name Default directly into powershell it works as expected returning the list of two. 更令人困惑的是,当我调用import-module webadministrationget-webvirtualdirectory -name Default直接放入powershell,它按预期方式工作,返回两个列表。

确保IIS连接池进程正在以管理员权限运行。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM