Swagger自定义默认首页


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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM