Почему Server.MapPath добавляет дополнительный каталог в путь - PullRequest
0 голосов
/ 05 февраля 2019

Я использую функцию HttpContext.Current.Server.MapPath, чтобы найти файл StudentReport.rdlc, который находится под Class Library Project.

Структура решения:

enter image description here

Я вызываю функцию ниже, которая находится в Class Library Project из 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, но все равно он добавляет каталог WebDemo во все пути.

Текущий путь:

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

Ожидаемый путь:

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

Могу ли я знать, почему это происходит?

Любая помощь будет отличной.

...