代码之家  ›  专栏  ›  技术社区  ›  Shaiju T

为什么Server.MapPath在路径中添加了额外的目录

  •  1
  • Shaiju T  · 技术社区  · 6 年前

    我在用 HttpContext.Current.Server.MapPath 函数来定位 StudentReport.rdlc 文件在 Class Library Project .

    解决方案结构:

    enter image description here

    我正在调用下面的函数 从一个 Web API Project 命名为 WebDemo .

    public class Reports
    {
        public string GetReportPath()
        {
    
            string path1 = System.AppDomain.CurrentDomain.BaseDirectory;
    
            var path2 = System.Web.HttpContext.Current.Server.MapPath("~/StudentReport.rdlc");
    
            var path3 = System.Web.HttpContext.Current.Server.MapPath("~/BL/ClassLib/StudentLib
                                                    /Reports/StudentReport.rdlc");
    
            var path4 = System.Web.HttpContext.Current.Server.MapPath("~/StudentLib/Reports
                                                    /StudentReport.rdlc");
    
            string path5 = System.Web.Hosting.HostingEnvironment.MapPath("~/StudentLib/Reports
                                                    /StudentReport.rdlc");
    
            return path5;
        }
    }
    

    如你所见,我试过所有的组合 Server.MapPath 网络演示

    当前路径:

    "C:\\Users\\tom\\source\\repos\\WebDemo\\WebDemo\\StudentLib\\Reports\\StudentReport.rdlc"
    

    预期路径:

    "C:\\Users\\tom\\source\\repos\\WebDemo\\StudentLib\\Reports\\StudentReport.rdlc"
    

    我能知道为什么会这样吗?

    0 回复  |  直到 6 年前
    推荐文章