1、添加资源文件夹
①创建wwwroot->html->index.html文件
②、文件属性【生成操作】设置成【嵌入的资源】
③、配置Swagger管道
app.UseSwaggerUI(option =>
{
option.IndexStream = (Func<Stream>) (() => Assembly.GetExecutingAssembly()
.GetManifestResourceStream("GreenUnity.GuangMing.WebApi.wwwroot.html.index.html"));
});
④、获取Swagger默认index.html替换资源文件【官网地址:https://github.com/swagger-api/swagger-ui/blob/master/dist/index.html】
Stream _stream= (Func<Stream>) (() => typeof (SwaggerUIOptions).GetTypeInfo().Assembly.GetManifestResourceStream("Swashbuckle.AspNetCore.SwaggerUI.index.html"));
byte[] _byte=new byte[_stream.Length];
_stream.Read(_byte,0,_byte.Length);
string _html=Encoding.UTF8.GetString(_byte);