且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET Core 2.1中的UseStaticFiles,UseSpaStaticFiles和UseSpa有什么区别?

更新时间:2021-10-16 22:44:46

静态文件(例如HTML,CSS,图像和JavaScript)是资产 ASP.NET Core应用程序直接为客户提供服务.一些配置是 必须启用这些文件.

Static files, such as HTML, CSS, images, and JavaScript, are assets an ASP.NET Core app serves directly to clients. Some configuration is required to enable serving of these files.

  • UseStaticFiles-在Web根目录(wwwroot文件夹)内提供文件

    • UseStaticFiles - Serve files inside of web root (wwwroot folder)

      UseSpaStaticFiles-为资产中的图像,css,js之类的静态文件提供服务 角度应用程序的文件夹

      UseSpaStaticFiles - Serve static file like image, css, js in asset folder of angular app

      UseSpa-让asp.net核心知道您要运行哪个目录 angular应用,在生产模式下运行时是什么dist文件夹,以及 哪个命令可以在开发模式下运行angular app

      UseSpa - let asp.net core know which directory you want to run your angular app, what dist folder when running in production mode and which 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");
          }
      });