事实证明,该应用程序不允许对
node_modules
文件夹[1]。在应用程序运行之前,我对其进行了许多小改动,今天晚些时候我将在这里进行修改,但最重要的是
Startup
:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseDefaultFiles();
app.UseStaticFiles();
UseCustomFileServer(app, env);
}
private void UseCustomFileServer(IApplicationBuilder app, IHostingEnvironment env)
{
// this will serve up wwwroot
app.UseFileServer();
// this will serve up node_modules
var provider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "node_modules"));
var options = new FileServerOptions();
options.RequestPath = "/node_modules";
options.StaticFileOptions.FileProvider = provider;
options.EnableDirectoryBrowsing = true;
app.UseFileServer(options);
}
我认为,由于一些糟糕的设计,
UseStaticFiles
wwwroot
,所以我不得不补充
UseFileServer
对于
[1] NET核心web应用程序默认情况下根本不允许提供任何静态文件。您必须添加
Microsoft.AspNetCore.StaticFiles
程序包到
project.json
,并将这两行添加到
Startup.Configure()
app.UseDefaultFiles();
app.UseStaticFiles();