3

I have a ASP.NET Core Web Application using a SQlite database. This works perfect, but now I want to host it in azure. Where should i put my *.db file? I suppose the wwwroot folder is not the best place as it can be browsable!

There used to be the App_Data folder for this. Where should these kind of files go in ASP.NET Core?

Thanks for the hints...

2 Answers 2

4

So what I found out is that if you use the following setting:

"ConnectionStrings": {
   "DefaultConnection": "Data Source=.\\DbName.db" 
}

The database file will be automatically placed in the root folder of the Web Application on Azure and not as I thought into the wwwroot. So this works perfectly for me and brings the advantage that no directory exist check has to be done before creating the database file.

Sign up to request clarification or add additional context in comments.

Comments

0

The easiest way to do this would be to upload the database right in your root directory. That means the directory where you have your {WebsiteName.dill} or WebApplication.dll by default. For Azure, this would be your D:\home\site\wwwroot directory (note that this is not the wwwroot folder for static files in your application, but rather, the root folder in azure also named wwwroot). Then you would connect to this database with a connection string in your appsettings.Production.json file like so.

"ConnectionStrings": {
    "DefaultConnection": "Data Source=<DATABASE_NAME>.db"
  }

. That should do the trick.

2 Comments

But shouldn't data files be outside of wwwroot? I mean that is the place for static files that get hosted. So that is kinda the wrong place IMO.
Yes, you can totally put it outside of the wwwroot folder. Just make sure to use an appropriate directory for your connection strings. I said to place it in the wwwroot folder so as to provide you with the easiest example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.