Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why need to set up "UseContentRoot(AppContext.BaseDirectory) in ASP.NET Core MVC"?

Tags:

asp.net-core

Why need to set up UseContentRoot(AppContext.BaseDirectory) in ASP.NET Core MVC?

image

like image 359
SmileEyes Avatar asked Feb 17 '17 07:02

SmileEyes


People also ask

Why do we need core in asp net?

ASP.NET Core provides the following benefits: A unified story for building web UI and web APIs. Architected for testability. Razor Pages makes coding page-focused scenarios easier and more productive.

What is .netcore MVC?

The ASP.NET Core MVC framework is a lightweight, open source, highly testable presentation framework optimized for use with ASP.NET Core. ASP.NET Core MVC provides a patterns-based way to build dynamic websites that enables a clean separation of concerns.


1 Answers

From the docs (which in this case I wrote):

Specifying Directory.GetCurrentDirectory as the content root will use the web project's root folder as the app's content root when the app is started from this folder (for example, calling dotnet run from the web project folder). This is the default used in Visual Studio and dotnet new templates.

If you don't add this, the content root will default to the application root, which is wherever the program is running from (probably somewhere in a /bin folder). This usually isn't what you want if you're launching the web app from its source/project root.

like image 61
ssmith Avatar answered Sep 28 '22 20:09

ssmith