英文:
How to find the full virtual path of an IIS VirtualDirectory?
问题
I'm trying to programmatically get a list of all the applications running on an IIS website, but when I query VirtualDirectory.Path
I only ever get back "/", even though IIS shows the full path as expected.
I used the following script to reproduce my problem. I'm using pythonnet to interface with the C# API:
#! python3
import clr
import os
webAdmin = "system32\\inetsrv\\Microsoft.Web.Administration.dll"
clr.AddReference(os.path.join(os.environ["SystemRoot"], webAdmin))
from Microsoft.Web.Administration import ServerManager
def main():
manager = ServerManager.OpenRemote("localhost")
site = manager.Sites["Default Web Site"]
poolName = "test-app-pool"
manager.ApplicationPools.Add(poolName)
newApp = site.Applications.Add("/another-test", "C:\\some\\path")
newApp.ApplicationPoolName = poolName
manager.CommitChanges()
print(newApp.VirtualDirectories[0].Path)
# Output: /
if __name__ == "__main__":
main()
I expected the output to be "/another-test". Looking at the documentation it says VirtualDirectory.Path "Gets or sets the virtual path of the virtual directory relative to its parent". If I loop through all the applications and all the virtual directories on the site, each of them has a .Path of "/". How do I get the full virtual path?
英文:
I'm trying to programmatically get a list of all the applications running on an IIS website, but when I query VirtualDirectory.Path
I only ever get back "/", even though IIS shows the full path as expected.
I used the following script to reproduce my problem. I'm using pythonnet to interface with the C# API:
#! python3
import clr
import os
webAdmin = "system32\\inetsrv\\Microsoft.Web.Administration.dll"
clr.AddReference(os.path.join(os.environ["SystemRoot"], webAdmin))
from Microsoft.Web.Administration import ServerManager
def main():
manager = ServerManager.OpenRemote("localhost")
site = manager.Sites["Default Web Site"]
poolName = "test-app-pool"
manager.ApplicationPools.Add(poolName)
newApp = site.Applications.Add("/another-test", "C:\\some\\path")
newApp.ApplicationPoolName = poolName
manager.CommitChanges()
print(newApp.VirtualDirectories[0].Path)
# Output: /
if __name__ == "__main__":
main()
I expected the output to be "/another-test". Looking at the documentation it says VirtualDirectory.Path "Gets or sets the virtual path of the virtual directory relative to its parent". If I loop through all the applications and all the virtual directories on the site, each of them has a .Path of "/". How do I get the full virtual path?
答案1
得分: 0
我相信你正在寻找的是Application类的Path属性,即newApp.Path
包含你想要的内容。
英文:
I believe what you are looking for is Path property of the Application class, i.e. newApp.Path
contains what you want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论