本文主要是介绍IIS网站允许3D模型类型的文件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参与threejs项目的研发,本地开发完成后,发布后使用时发现模型文件不能正常获取资源,原因是IIS站点默认不支持模型类型。
一开始是通过直接在IIS网站管理中的类型添加来实现网站对类型的支持。
后来发现一段对于后端来说可以直接实现代码上添加类型支持的方式,尚未未验证,以作记录。
核心代码:
var app = builder.Build();
// Set up custom content types - associating file extension to MIME type
var provider = new FileExtensionContentTypeProvider();
// Add new mappings
provider.Mappings[".fbx"] = "application/octet-stream";
provider.Mappings[".glb"] = "application/octet-stream";
//provider.Mappings[".png"] = "image/png";
app.UseStaticFiles(new StaticFileOptions
{ContentTypeProvider = provider
});
完整代码:
Program.cs
using Furion;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.StaticFiles;
using SQLitePCL;
using YDCMES.Application;
using YDCMES.Core.Util;
using YDCMES.EntityFramework.Core;
using YDCMES.Web.Core;var builder = WebApplication.CreateBuilder(args).Inject();
builder.Host.UseSerilogDefault().ConfigureAppConfiguration((hostingContext, config) => {config.AddJsonFile("applicationsettings.json", optional: true, reloadOnChange: true);
});
builder.Services.AddSingleton(new Appsettings(builder.Configuration));
//builder.Services.Configure<RefreshRate>(builder.Configuration.GetSection(RefreshRate.key));
//var origins = App.GetConfig<AddCorsDto>("CorsAccessorSettings");
var policyName = "Default";
// var withOrigins = origins.WithOrigins.ToArray();
builder.Services.AddCors(options =>
{options.AddPolicy(policyName, policy =>{policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();});
});
//Sqlite上下文
builder.Services.AddDbContext<SqliteDbContext>(options =>
{//options.UseSqlite($"Filename={AppContext.BaseDirectory}ACS.db;Pooling=true;");
});
var app = builder.Build();
// Set up custom content types - associating file extension to MIME type
var provider = new FileExtensionContentTypeProvider();
// Add new mappings
provider.Mappings[".fbx"] = "application/octet-stream";
provider.Mappings[".glb"] = "application/octet-stream";
//provider.Mappings[".png"] = "image/png";
app.UseStaticFiles(new StaticFileOptions
{ContentTypeProvider = provider
});
app.UseCors(policyName);
app.Run();
这篇关于IIS网站允许3D模型类型的文件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!