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

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.

主站蜘蛛池模板: 施秉县| 兴文县| 济源市| 阿巴嘎旗| 岢岚县| 龙州县| 方城县| 张北县| 巴东县| 壤塘县| 东海县| 武功县| 安远县| 阿尔山市| 宕昌县| 花垣县| 柏乡县| 宜都市| 张家口市| 山东省| 吉安县| 蓝山县| 巴青县| 固阳县| 上饶县| 旬阳县| 双江| 天台县| 藁城市| 金门县| 屏山县| 桂阳县| 平湖市| 湖州市| 收藏| 武义县| 孟州市| 明光市| 浦江县| 云龙县| 凤冈县|