Use Server.MapPath in the business layer

My business layer creates files and should save them in the App_Data folder of my asp.net mvc 4 web interface.

I could use Server.MapPath at the business level to get the physical path to the App_Data folder. But I want to avoid the System.Web link at the business level.

Are there other ways to get the path to App_Data in the business layer?

+6
c # asp.net-mvc server.mappath business-layer
Sep 06
source share
3 answers

The right way to handle this is to have the presentation layer go all the way to the business layer.

To do this in another way, the goal of creating a business layer is to create a separation of problems between ui and business processes. If you force the business process to know about the ui layer, you are breaking this separation of concerns.

There are several ways you could handle this. You can pass the path to the business layer when the business layer is being built, for example, through initialization of the constructor or through dependency injection. Or you can pass it to a method call. Or you can create a configuration file that loads your business layer containing this path.

There are many ways to get around this so as not to disturb the separation of problems.

+26
Sep 06 '12 at 7:11
source share

you can use

 string path = System.AppDomain.CurrentDomain.BaseDirectory+"App_Data"; 
+15
Dec 04 '13 at 5:30
source share
 string path = HostingEnvironment.MapPath("~\\App_Data"); 

It works for me

+5
Sep 12 '15 at 5:38
source share



All Articles