.net上本地加载模型出错

我想要本地加载模型,模型文件是通过https://extract.autodesk.io转...,在node.js上是可以运行,但是在.net上却加载失败了。文件的地址也没出错,请问这是怎么回事啊》`

    var initOptions = {
        path: 'r8/0.svf',
        env: ''
    }
    function onEnvInitialized() {

        var domContainer = document.getElementById('viewer')
        var viewer = new Autodesk.Viewing.Private.GuiViewer3D(domContainer)
        var result = viewer.start()
        var core = viewer.loadModel(initOptions.path)
    }
    Autodesk.Viewing.Initializer(
        initOptions,
        function () {
            onEnvInitialized()
        })`
      

图片描述

阅读 2.1k
1 个回答

找到原因了。因为服务器无法解析SVF格式。所以要设置MIME Type。在.NET Web.config文件中添加以下MIME类型

<system.webServer>
    <staticContent>
      <mimeMap fileExtension=".svf" mimeType="application/octet-stream "/>
      <mimeMap fileExtension=".pf" mimeType="application/octet-stream "/>
      <mimeMap fileExtension=".pack" mimeType="application/octet-stream "/>
    </staticContent>

  </system.webServer>

而在.NET Core中则必须在Startup.cs文件中Configure方法内添加MIME类型。并且因为.net core不是从默认路径浏览静态文件。所以必须指定静态文件目录,并且把SVF文件放在那个目录中服务器才能访问。

  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                {
                    HotModuleReplacement = true
                });
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseAuthentication();
            app.UseHttpsRedirection();
            app.UseCookiePolicy();
            
            app.UseStaticFiles();
            
            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".svf"] = "application/octet-stream";
            provider.Mappings[".pf"] = "application/octet-stream";
            provider.Mappings[".pack"] = "application/octet-stream";
            app.UseStaticFiles(new StaticFileOptions {
                ContentTypeProvider = provider,
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(env.ContentRootPath, @"MyStaticFiles")),
                RequestPath = new PathString("/StaticFiles")
            });

         
        }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题