ASP.NET Core Interview Question #42

What is the difference between ContentRootPath and WebRootPath?

Application Structure & Configuration Junior Beginner

Quick Interview Answer

ContentRootPath is the base path for application content such as configuration files, Razor files, and other project content. It is normally the directory containing the application.

Detailed Explanation

ContentRootPath is the base path for application content such as configuration files, Razor files, and other project content. It is normally the directory containing the application.

WebRootPath is the base path for publicly served web assets and normally points to the wwwroot directory.

The distinction is important because files under the content root are application resources, while files under the web root may be directly accessible to clients when static file middleware is enabled.

Code Example

public class PathService
{
    public PathService(IWebHostEnvironment env)
    {
        var contentRoot = env.ContentRootPath;
        var webRoot = env.WebRootPath;
    }
}