好的,通过一些小调查,我能够解决我的问题,这也可能帮助您解决问题。
在服务器端设置 UseStaticFiles 时,您应该添加一些选项以允许访问 UnkownType 文件。
有两种方法可以解决这个问题。首先是指定您希望以这种方式提供的文件的类型。在这种情况下,您应该在 Startup.cs 文件 Configure 函数上这样做:
StaticFileOptions options = new StaticFileOptions { ContentTypeProvider = new FileExtensionContentTypeProvider() };
((FileExtensionContentTypeProvider)options.ContentTypeProvider).Mappings.Add(new KeyValuePair<string, string>(".glb", "model/gltf-buffer"));
app.UseStaticFiles(options);
第二个选项(如果您有超过 1 个 Unkown 文件类型,则更合适)是允许任何 UnkownTypeFile 在同一 Configure 函数中使用同一 StaticFileOptions 上的标志:
StaticFileOptions options = new StaticFileOptions { ContentTypeProvider = new FileExtensionContentTypeProvider() };
options.ServeUnknownFileTypes = true;
app.UseStaticFiles(options);
另外,请确保您能够访问服务器上的子域目录。如果你不是,那么你也应该在 Startup.cs 文件中的ConfigureServices 函数中包含它:
services.AddDirectoryBrowser();
以及同一文件中Configure 函数中的以下行:
app.UseFileServer(enableDirectoryBrowsing: true);
注意:此解决方案适用于使用 .Net Core 3.1 的服务器。如果您使用不同的版本或 .Net Framework,可能会有不同的修复。