问题描述
我有一个 .Net Core API 和一个使用 Babylonjs 来渲染一些 3D 模型的 React 应用程序。在我的服务器端,我存储了客户端将请求渲染到场景中的 3D 模型。为此,我在我的 .Net Core 服务器上允许 UseFileServer
和 UseStaticFiles
。我还创建了一个政策来申请需要 CORS 政策的请求。我实施的政策如下:
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",policyBuilder => policyBuilder
.AllowAnyHeader()
.SetIsOriginAllowedToAllowWildcardSubdomains()
.AllowAnyMethod()
.SetIsOriginAllowed((host) => true)
.AllowCredentials());
});
我将其应用于以静态文件为目标的请求,方式如下:
app.UseFileServer(enableDirectorybrowsing: true);
app.UseStaticFiles(fileOptions);
在客户端,Babylon 库通过以下方式完成请求:
SceneLoader.ImportMeshAsync(
"","http://localhost:9001/resources/objects/","sphere.glb",scene
)
.then((result) => {
result.renderingGroupId = 1;
scene.createDefaultCamera(true,true,true);
scene.activeCamera.alpha += Math.PI;
})
.catch((error) => {
return null;
});
发生的情况是我仅在 google chrome 上收到以下错误,在 Firefox 和 Opera 上都没有。
此外,对 Firefox 和 Opera 的响应包含缺少的标头,而对 chrome 的响应则没有。
铬:
火狐:
歌剧: