Blazor 服务器端看不到 GLTF 文件

Blazor-server-side can't see GLTF files

我使用 iis 在 Azure 上托管了我的 Blazor 应用程序

获得了一些我想使用 three.js 访问的 GLTF 文件,但它就像我的应用程序无法看到我的任何 GLTF 文件。

我在 IIS 管理器的 Blazor 应用程序中添加了一个虚拟目录。 (E://Output) 在 IIS 中添加为 wwwroot

旁边的虚拟文件夹

如果我转到 https://xxxxx.com/output/637650602249582109_Output/VisData/room.bin(此文件存在,它将开始下载)

如果我去 https://xxxxx.com/output/637650602249582109_Output/VisData/scene.gltf 它给了我一个 404 ..

我试图在我的启动中添加这个:

app.UseStaticFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                ServeUnknownFileTypes = true,
                DefaultContentType = "text/plain"
            });

它有点帮助我包含在项目 wwwroot 文件夹中的文件 (wwwroot/VisData/scene.gltf)

https://xxxxx.com/VisData/scene.gltf

但是我通过虚拟驱动器包含的文件做错了什么?

尝试将 GLTF 文件扩展名 .gltf 添加到您的 IIS,.bin 已被映射:

这可以通过依赖注入来完成,只需将以下内容添加到您的Program.cs

using Microsoft.AspNetCore.StaticFiles;


...


builder.Services.Configure<StaticFileOptions>(options =>
{
    options.ContentTypeProvider = new FileExtensionContentTypeProvider
    {
        Mappings =
        {
            [".gltf"] = "model/gltf+json",
            [".glb"] = "model/gltf-binary",
            [".bin"] = "application/octet-stream"
        }
    };
});

带有替代选项的完整文档:

https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/static-files?view=aspnetcore-6.0#blazor-server-file-mappings-and-static-file-options