【发布时间】:2016-06-05 22:20:31
【问题描述】:
我一直在查看网络,但仍然没有运气,因此我问这个问题。 我有一个 WEB API 4.6 项目,它也是 angularjs2 应用程序的所在地, 我已经设置为使用这样的静态文件:
var physicalFileSystem = new PhysicalFileSystem(@".\wwwroot\");
var options = new FileServerOptions
{
EnableDefaultFiles = true,
FileSystem = physicalFileSystem,
};
var contentTypes = new FileExtensionContentTypeProvider();
options.StaticFileOptions.FileSystem = physicalFileSystem;
options.StaticFileOptions.ServeUnknownFileTypes = true;
options.StaticFileOptions.ContentTypeProvider = contentTypes;
options.DefaultFilesOptions.DefaultFileNames = new[] { "index.html" };
options.EnableDirectoryBrowsing = true;
app.UseFileServer(options);
index.html 已提供服务,当 index.html 尝试获取所有文件 (.css.js) 时,控制台中会显示 404 错误。我启用了目录浏览,我看到文件在那里。
【问题讨论】:
-
只是好奇!为什么需要上面的代码来处理静态文件?我运行的 MVC 项目确实有一个 MVC 应用程序、WebAPI 端点和 Angular JS 静态文件。没有上面的代码,一切似乎都可以工作。
-
我没有使用 mvc,我有一个单独的 angularjs2 项目,我只想在 wwwroot 下构建它
标签: javascript c# asp.net .net-4.6