简体   繁体   中英

How to give virtual directory path in application

I have a virtual directory in IIS just under the application folder like

MyApplication/VirtualDirectory 

IIS 中的文件夹结构(请忽略命名约定,因为它只是为了表示目的)

I wish to access this VirtualDirectory in my application, things that I've tried are like :

string[] imageDir = null;
string sourceFilePath = "Myapplication/VirtualDirectory"; 
/* ./Myapplication/VirtualDirectory
~/Myapplication/VirtualDirectory
\Myapplication/VirtualDirectory
.\Myapplication/VirtualDirectory
~\Myapplication/VirtualDirectory*/
imageDir = Directory.GetDirectories(sourcePath);

Please let me know if any additional data is needed, Thanks.

string[] imageDir = null;
string sourceFilePath = "~/VirtualDirectory"; 

You can try below code, and you need to use ServerManager Class.

ServerManager serverManager = new ServerManager();
 // get the site (e.g. default)
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
 // get the application that you are interested in
Application myApp = site.Applications["/Dev1"];
 // get the physical path of the virtual directory
Console.WriteLine(myApp.VirtualDirectories[0].PhysicalPath);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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