Why need to set up UseContentRoot(AppContext.BaseDirectory)
in ASP.NET Core MVC?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With