- Hands-On Full:Stack Web Development with ASP.NET Core
- Tamir Dresher Amir Zuker Shay Friedman
- 226字
- 2021-06-10 19:37:24
Serving default documents
The frontend of modern web applications consists mostly of static files. Therefore, pointing the server to the client directory and instructing it to serve its entire content as static files is a common practice. In such situations, you will also want to send the user the main application file, such as index.html, when they navigate to the static folder. These files are called default documents.
Defining default documents for a static folder is done via the UseDefaultFiles method. Within the Startup.cs file, locate the Configure method and add the following marked line:
app.UseDefaultFiles();
app.UseStaticFiles();
The UseDefaultFiles method instructs ASP.NET Core to look for the following files once a URL that directs to a static folder has been detected:
- default.htm
- default.html
- index.htm
- index.html
These files will be looked for in that order. Once a filename matching one of these names is found, it will be served to the end user.
To change the filenames that UseDefaultFiles searches for, create and set a DefaultFilesOptions object and pass it to the method. For example, the following code changes the default filename collection to look for the main.htm and main.html files, instead of the predefined filenames:
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("main.htm");
options.DefaultFileNames.Add("main.html");
app.UseDefaultFiles(options);
- 自動駕駛網(wǎng)絡(luò):自智時代的網(wǎng)絡(luò)架構(gòu)
- 物聯(lián)網(wǎng)網(wǎng)絡(luò)安全及應(yīng)用
- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- Learning QGIS 2.0
- Proxmox High Availability
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要2
- SSL VPN : Understanding, evaluating and planning secure, web/based remote access
- 智慧光網(wǎng)絡(luò):關(guān)鍵技術(shù)、應(yīng)用實踐和未來演進(jìn)
- 通信原理及MATLAB/Simulink仿真
- 網(wǎng)絡(luò)環(huán)境中基于用戶視角的信息質(zhì)量評價研究
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實戰(zhàn)指南
- 全聯(lián)網(wǎng)標(biāo)識服務(wù)
- 工業(yè)以太網(wǎng)技術(shù):AFDX/TTE網(wǎng)絡(luò)原理、接口、互連與安全
- 人際網(wǎng)絡(luò)
- NB-IoT原理和優(yōu)化