Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App_Data directory in ASP.NET5 MVC6

Tags:

I've been trying ASP.NET5 MVC6 app. In the previous version, there was a directory App_Data. I used this folder to store error logs. But it is not found in latest version. Any help?

like image 654
s.k.paul Avatar asked Jul 23 '15 05:07

s.k.paul


People also ask

What is App_Data folder in asp net?

App_Data contains application data files including . mdf database files, XML files, and other data store files. The App_Data folder is used by ASP.NET to store an application's local database, such as the database for maintaining membership and role information.

What is the use of App_Data folder in MVC?

The App_Data folder of MVC application is used to contain the application related data files like . mdf files, LocalDB, and XML files, etc. The most important point that you need to remember is that IIS is never going to serve files from this App_Data folder.

What goes in the Model folder?

The Models folder contains model class files. Typically model class includes public properties, which will be used by the application to hold and manipulate application data.


2 Answers

This works for ASP.NET MVC with Core 2

public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // Use this code if you want the App_Data folder to be in wwwroot //string baseDir = env.WebRootPath;  // Use this if you want App_Data off your project root folder string baseDir = env.ContentRootPath;  AppDomain.CurrentDomain.SetData("DataDirectory", System.IO.Path.Combine(baseDir, "App_Data")); } 

Now you can put this code where you need it to get your App_Data folder

string dataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); 
like image 84
Robert Stevens Avatar answered Oct 16 '22 07:10

Robert Stevens


I think putting App_Data under wwwroot is a bad idea. With asp.net 5 when we publish/deploy we get 2 folders approot and wwwroot. Any files that are not going to be served by http requests should not live under wwwroot. It would be better for things that previously would go under App_Data folder to live somewhere under approot instead. This related question of how to access files from approot should be of help

like image 28
Joe Audette Avatar answered Oct 16 '22 06:10

Joe Audette