使用Server.Mappath不返回映射到虚拟目录的正确的物理路径的web应用程序的子文件夹 [英] Server.MapPath does not return the right physical path mapped to a virtual directory in Web-App subfolder

查看:746
本文介绍了使用Server.Mappath不返回映射到虚拟目录的正确的物理路径的web应用程序的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个网站,它映射到 D:\\ MyWebApp 插件子目录创建一个虚拟目录,并将其映射到 D:\\项目\\ presentation \\网络\\会计
问题是,当我想要得到的物理路径的的http://本地主机/插件/会计我得到错误的结果。

I create a web site and mapped it to the D:\MyWebApp and in Plugins sub directory I create a virtual directory and mapped it to D:\Project\Presentation\Web\Accounting. the problem is when I want to get the physical path of thehttp://localhost/Plugins/Accounting I get wrong result.

两者使用Server.Mappath(〜/插件/会计)使用Server.Mappath(/插件/会计)返回D:\\ MyWebApp \\插件\\会计是物理上不存在。我想获得 D:\\项目\\ presentation \\网络\\会计
我寻找它和刚刚获得以下行:

both Server.MapPath("~/Plugins/Accounting") and Server.MapPath("/Plugins/Accounting") returns 'D:\MyWebApp\Plugins\Accounting' that does not exist physically. I want to get D:\Project\Presentation\Web\Accounting. I search for it and just get below lines:


  1. 使用Server.Mappath(。)返回文件的当前物理目录(如C ++)执行

  2. 使用Server.Mappath()返回上一级目录

  3. 使用Server.Mappath(〜)返回给应用程序的根目录的物理路径

  4. 使用Server.Mappath(/)返回到域名的根目录的物理路径(不一定是相同的应用程序的根目录)

但在我的情况下(在一个子文件夹中的虚拟目录),它不工作!
我用IIS8和Asp.Net MVC的4和C#4。
我怎样才能得到呢?

but in my case (virtual directory in a subfolder), it's not work !!! I use IIS8 and Asp.Net-Mvc 4 and C#4. how can I get this?

推荐答案

试试这个

删除

要求的http://本地主机/插件/会计 使用Server.Mappath(〜/)方式给路径的应用程序文件夹..

on request http://localhost/Plugins/Accounting Server.MapPath("~/") method give path to your application folder..

Server.MapPath("~/Accounting/");//path to your Accounting folder

这篇关于使用Server.Mappath不返回映射到虚拟目录的正确的物理路径的web应用程序的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆