![](/img/trans.png)
[英]Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS
[英]Server.MapPath does not return the right physical path mapped to a virtual directory in Web-App subfolder
我创建了一个网站并将其映射到D:\\MyWebApp
并在Plugins
子目录中创建了一个虚拟目录并将其映射到D:\\Project\\Presentation\\Web\\Accounting
。 问题是,当我想获得http://localhost/Plugins/Accounting
的物理路径时,我得到了错误的结果。
Server.MapPath("~/Plugins/Accounting")
和Server.MapPath("/Plugins/Accounting")
返回物理上不存在的“D:\\ MyWebApp \\ Plugins \\ Accounting”。 我想得到D:\\Project\\Presentation\\Web\\Accounting
。 我搜索它,然后到达下面的行:
但在我的情况下(子文件夹中的虚拟目录),它不起作用! 我使用IIS8和Asp.Net-Mvc 4和C#4。 我怎么能得到这个?
试试这个
删除“/ plugin”
根据请求http://localhost/Plugins/Accounting
Server.MapPath(“〜/”)方法提供应用程序文件夹的路径。
Server.MapPath("~/Accounting/");//path to your Accounting folder
用这个,
Request.PhysicalApplicationPath + "Plugins\\Accounting\\
问题是你有一个虚拟目录,它将重置asp.net认为是你的应用程序的基本目录。 它真的需要在虚拟目录中吗? 如果是这样,您可以尝试检查Request.ApplicationPath以找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.