问题描述
ASP.NET Core 2.1.1 为 appBuilder 提供了几个看似相关的扩展方法:
ASP.NET Core 2.1.1 offers several seemingly related extension methods for appBuilder:
UseStaticFiles
来自Microsoft.AspNetCore.StaticFiles
UseSpaStaticFiles
来自Microsoft.AspNetCore.SpaServices.Extensions
UseSpa
来自Microsoft.AspNetCore.SpaServices.Extensions
UseStaticFiles
fromMicrosoft.AspNetCore.StaticFiles
UseSpaStaticFiles
fromMicrosoft.AspNetCore.SpaServices.Extensions
UseSpa
fromMicrosoft.AspNetCore.SpaServices.Extensions
请帮我弄清楚它们的目的和相互之间的关系?
另外,如果我以不同的顺序运行这些方法,从服务器执行的角度来看有什么不同
Also, is there any difference from the server execution standpoint if I run these methods in a different order
例如
app.UseStaticFiles() -> app.UseSpaStaticFiles() -> app.UseSpa()
对比
app.UseSpa() -> app.UseSpaStaticFiles() -> app.UseStaticFiles()
推荐答案
UseStaticFiles - 在 Web 根目录(wwwroot 文件夹)中提供文件
UseStaticFiles - Serve files inside of web root (wwwroot folder)
UseSpaStaticFiles - 在资产中提供静态文件,如图像、css、jsangular 应用文件夹
UseSpaStaticFiles - Serve static file like image, css, js in assetfolder of angular app
UseSpa - 让 asp.net core 知道你想运行哪个目录angular 应用程序,在生产模式下运行时的 dist 文件夹和在开发模式下运行 angular 应用程序的命令
UseSpa - let asp.net core know which directory you want to run yourangular app, what dist folder when running in production mode andwhich command to run angular app in dev mode
例子
services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } });
这篇关于ASP.NET Core 2.1 中的 UseStaticFiles、UseSpaStaticFiles 和 UseSpa 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!