开发者

How can I change a virtual directory's physical path in IIS7 and C#?

开发者 https://www.devze.com 2022-12-25 18:06 出处:网络
I need to change the where a virtual directory\'s physical path is in C#. This is executed via an installer so it will be running on the machine where the virtual directory resides.

I need to change the where a virtual directory's physical path is in C#. This is executed via an installer so it will be running on the machine where the virtual directory resides.

This is what I have so far:

 using (DirectoryEntry webSiteRoot = WmiUtility.GetWebSiteRootDirectory(webSite))
            {
                DirectoryEntry virtualDirectory =
                    WmiUtility.GetVirtualDirectoryByName(web开发者_C百科SiteRoot, vDirName);

                string currentPath = virtualDirectory.Path;


                    virtualDirectory.Path = "C:\somepath"
                    srvMgr.CommitChanges();

It would appear that the VirtualDirectory.Path is not a physical one. Any help?

UPDATE:

virtualDirectory.Properties["Path"].Value = "c:\newlocation";

                    srvMgr.CommitChanges();

DirectoryEntry property "Path" contains the local, physical, location that I need to change. But for some reason the above does nothing. I don't see any exceptions but the properties value seems unchanged.


My Bad. I was committing changes on the ServerManager rather than on the VirtualDirectory.

virtualDirectory.CommitChanges();


HttpServerUtility.MapPath('~/Virtual');
0

精彩评论

暂无评论...
验证码 换一张
取 消