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