【问题标题】:HttpContext.Current.Server.MapPath() returning inconsistent resultsHttpContext.Current.Server.MapPath() 返回不一致的结果
【发布时间】:2021-02-17 16:57:18
【问题描述】:

HttpContext.Current.Server.MapPath() 遇到了一个奇怪的问题。 如果我打电话

HttpContext.Current.Server.MapPath("/")

HttpContext.Current.Server.MapPath("~")

我得到了“C:\GitHub\MyWebApp”,这是我所期望的。但如果我打电话

HttpContext.Current.Server.MapPath("/folder")

HttpContext.Current.Server.MapPath("~/folder")

我得到“C:\folder”。我希望得到“C:\GitHub\MyWebApp\folder”

我不明白这怎么会出错。 我正在使用 Visual Studio 2019 在 Windows 上运行 .Net 4.6.1 并进行调试,以防万一。

【问题讨论】:

    标签: c# asp.net webforms


    【解决方案1】:

    恐怕这有点尴尬 - 一个脚本在我的 IIS 配置中添加了一个虚拟文件夹,这会将“文件夹”重定向到“C:\folder”。回答是正确的,他们只是让我感到困惑,并且在提出问题之前我没有发现配置。

    感谢所有花时间思考这个问题的人。

    【讨论】:

      猜你喜欢
      • 2016-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多