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

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.

主站蜘蛛池模板: 北票市| 汝阳县| 连城县| 怀来县| 乌兰察布市| 镇康县| 五原县| 永登县| 奈曼旗| 靖安县| 清镇市| 佳木斯市| 德昌县| 柳河县| 漳平市| 千阳县| 芜湖市| 桓仁| 诏安县| 恩平市| 始兴县| 桂平市| 新平| 岢岚县| 九江县| 酒泉市| 平乡县| 合阳县| 蓬溪县| 兴安县| 资溪县| 阿尔山市| 清远市| 紫阳县| 三穗县| 图片| 佛山市| 黎川县| 桦南县| 三都| 郧西县|