Server.Mappath in C # classlibrary

How can I use the server.mappath method in a C # class library class that acts like my BusinessLayer for my ASP.NET website

+46
c # server.mappath
Jul 29 '09 at 11:11
source share
7 answers

Calling him up?

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

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

+109
Jul 29 '09 at 11:14
source share

You can get the base path using the following code and adding the path you need.

 string path = System.AppDomain.CurrentDomain.BaseDirectory; 
+16
Dec 04 '13 at 5:25
source share

You should contact System.Web and call:

  HttpContext.Current.Server.MapPath(...) 
+7
Jul 29 '09 at 11:14
source share

Perhaps you could abstract this as a dependency and create an IVirtualPathResolver. Thus, your service classes will not be tied to System.Web, and you can create another implementation if you want to reuse your logic in a different user interface technology.

+4
Apr 08 2018-12-12T00:
source share

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

 HostingEnvironment.MapPath("~/file") 

I wonder why no one mentioned it here.

+1
Jan 05 '16 at 12:19
source share

HostingEnvironment.MapPath

System.Web.Hosting.HostingEnvironment.MapPath (path);

+1
Jul 26 '16 at 11:16
source share

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

0
Sep 06 '17 at 6:49
source share



All Articles