- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 193字
- 2021-06-10 19:37:23
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.
推薦閱讀
- 數據通信網絡實踐:基礎知識與交換機技術
- 物聯網短距離無線通信技術應用與開發
- Building Django 2.0 Web Applications
- 工業控制網絡安全技術與實踐
- Oracle SOA Suite 11g Performance Tuning Cookbook
- 農產品物聯網研究與應用
- 面向物聯網的嵌入式系統開發:基于CC2530和STM32微處理器
- PLC、現場總線及工業網絡實用技術速成
- 精通SEO:100%網站流量提升密碼
- Laravel Application Development Cookbook
- 現場綜合化網絡運營與維護:運營商數字化轉型技術與實踐
- 物聯網M2M開發技術:基于無線CPU-Q26XX
- Hands-On Reactive Programming in Spring 5
- 物聯網與智慧廣電
- 現場總線與工業以太網及其應用技術(第2版)