【问题标题】:ASP .NET Core .glb file not found whereas the file was copy复制文件时未找到 ASP .NET Core .glb 文件
【发布时间】:2021-04-07 07:56:27
【问题描述】:

你好
我想导入一个 .glb 文件,但是当我在 JS 中调用它时,我收到一个错误,告诉我在复制文件时找不到该文件。 这是我的文件:
wwwroot
 /-Assets
 /---Element
 /---Objects3D
 /-----hub.glb 

在这里,错误:
Failed to load resource: the server responded with a status of 404 ()    :44353/Assets/Objects3D/hub.glb:1 

你有想法吗?
谢谢!

【问题讨论】:

  • 什么是 GLB 文件?
  • GLB 文件是存储 3D 模型的压缩文件
  • 你可以参考link,看看AlvinfromDiaspar的回答。

标签: javascript asp.net asp.net-core web


【解决方案1】:

好的,通过一些小调查,我能够解决我的问题,这也可能帮助您解决问题。

在服务器端设置 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,可能会有不同的修复。

【讨论】:

    猜你喜欢
    • 2016-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多