Skip to main content
 首页 » 编程设计

c#之我需要对 IIS 中的虚拟目录进行一些说明

2024年02月20日15qq号

好的。也许我做的不对,但我可以告诉你我在做什么,也许有人可以提供帮助。

我的应用程序位于 http:\localhost\MyApplication (c:\inetpub\wwwroot\MyApplication)。 现在我在 http:\localhost\MyApplication\ImagePaths 中创建了一个虚拟目录(指向 d:\images 文件夹)

在我的一个 aspx 页面中,我试图列出 http:\localhost\MyApplication\ImagePaths 虚拟目录中的所有图像。
我努力了: DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/ImagePaths"));目录包含 c:\inetpub\wwwroot\images !!??!?!?

这样做的正确方法是什么?我只想在我的应用程序外部创建一个目录并列出我的应用程序中的内容。

谢谢

请您参考如下方法:

我会使用 <appSettings>部分 web.config 并将其存储在那里:

<appSettings> 
   <add key="ImagesPath" value="D:\Images"/> 
</appSettings> 

然后从代码中,您可以通过以下方式访问它:

string imagesPath = ConfigurationManager.AppSettings["ImagesPath"]; 

和:

DirectoryInfo dir = new DirectoryInfo(imagesPath);