官术网_书友最值得收藏!

The content root and web root folders

ASP.NET Core defines two types of folders:

  • Content root: This is the root directory of the application. Any files outside this directory will not take part in the frontend application.
  • Web root: This is where static files are located.

By default, the content root is the root folder of the application, and the web root is the <content root>/wwwroot folder.

The web root folder is not exposed to the end user by default. Making it available to end users is described later in this chapter, under Setting the server to serve static files.

In large applications, the content root path might need to be changed. To do so, open the Program.cs file, locate the CreateWebHostBuilder static method, and add the following marked line to it:

WebHost.CreateDefaultBuilder(args)
.UseContentRoot(Path.Combine(Directory.GetCurrentDirectory(),
"/client"))
.UseStartup<Startup>()
.Build();

In this example, we're setting the path of the content root folder to <project root>/client.

In addition, the wwwroot folder name might not fit all scenarios. In order to change it, open the Program.cs file, find the BuildWebHost, and change it as follows:

WebHost.CreateDefaultBuilder(args)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseWebRoot("assets")
.UseStartup<Startup>()
.Build();

The highlighted line changes the web root path to <content root>/assets.

主站蜘蛛池模板: 贞丰县| 汉寿县| 台南县| 临泉县| 湖北省| 福建省| 洪泽县| 彰化县| 宜君县| 绥江县| 曲松县| 天全县| 新田县| 卫辉市| 丹阳市| 醴陵市| 敦煌市| 奉贤区| 仪征市| 泰兴市| 上虞市| 和田县| 朝阳市| 普陀区| 原阳县| 九台市| 绥中县| 东乡| 灵石县| 耒阳市| 福安市| 依安县| 湟中县| 元阳县| 株洲市| 钦州市| 呼玛县| 紫阳县| 介休市| 盱眙县| 荆门市|