Server.Mappath in C# classlibrary

前端 未结 7 1643

How can i use the server.mappath method in a C# class library class ,which acts as my BusinessLayer for My ASP.NET WEbsite

相关标签:
7条回答
  • 2020-12-13 12:41
    HostingEnvironment.MapPath
    System.Web.Hosting.HostingEnvironment.MapPath(path);
    
    0 讨论(0)
  • 2020-12-13 12:52

    By calling it?

    var path = System.Web.HttpContext.Current.Server.MapPath("default.aspx");
    

    Make sure you add a reference to the System.Web assembly.

    0 讨论(0)
  • 2020-12-13 12:52

    Use this System.Web.Hosting.HostingEnvironment.MapPath().

    HostingEnvironment.MapPath("~/file")
    

    Wonder why nobody mentioned it here.

    0 讨论(0)
  • 2020-12-13 13:00

    You can get the base path by using the following code and append your needed path with that.

    string  path = System.AppDomain.CurrentDomain.BaseDirectory;
    
    0 讨论(0)
  • 2020-12-13 13:00

    You should reference System.Web and call:

      HttpContext.Current.Server.MapPath(...)
    
    0 讨论(0)
  • 2020-12-13 13:00

    Architecturally, System.web should not be referred in Business Logic Layer (BLL). Employ BLL into the solution structure to follow the separate of concern principle so refer System.Web is a bad practice. BLL should not load/run in Asp.net context. Because of the reason you should consider using of System.AppDomain.CurrentDomain.BaseDirectory instead of System.Web.HttpContext.Current.Server.MapPath

    0 讨论(0)
提交回复
热议问题