如何获得虚拟目录的物理路径 [英] How to get virtual directory physical path
问题描述
我们知道虚拟目录可以链接到名称不同的文件夹,我如何获得虚拟目录的物理路径?
As we know that a virtual direcoty can be linked to a folder with a diffrent name, how can I get the physical path of a virtual directory ?
我一直在尝试使用HttpContext.Current.server.MapPath,但是即使目录不存在或名称不同,它也会返回物理路径以及我在参数中发送的路径.
I've been trying with HttpContext.Current.server.MapPath but it returns me the physic path plus the path I send in parameter even if the directory doesn't even exist or if it exists with a diffrent name.
示例:
C:\ blabla \ Sites \ Application1 \ Imaageesss -在光盘上
C:\blabla\Sites\Application1\Imaageesss - On disc
Application1 \ Images(在ISS中,我的重要目录)
Application1\Images (In ISS, my virutal directory)
但是,如果我在"/Images"上执行MapPath,它将永远不会给我 C:\ blabla \ Sites \ Application1 \ Imaageesss但是 C:\ inetpub \ wwwroot \ Images,它不是链接到的真实目录.
But if I do a MapPath on "/Images" it will never give me C:\blabla\Sites\Application1\Imaageesss but C:\inetpub\wwwroot\Images which is not the real directory linked to.
推荐答案
Server.MapPath("~/Images")
是正确的处理方法,因为〜"引用应用程序的根目录.
is the correct way to go about it as "~" references the root of your application.
这篇关于如何获得虚拟目录的物理路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!