加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-core – 虚拟目录中的IIS站点Swagger UI端点

发布时间:2020-12-15 23:55:56 所属栏目:asp.Net 来源:网络整理
导读:Swagger UI端点与登台时的dev不同(不包括域名) IIS配置 public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerFactory) app.UseSwagger(c= { //Change the path of the end point,should also update UI middle war
Swagger UI端点与登台时的dev不同(不包括域名)

IIS配置

public void Configure(IApplicationBuilder app,IHostingEnvironment env,ILoggerFactory loggerFactory)

 app.UseSwagger(c=>
        {
            //Change the path of the end point,should also update UI middle ware for this change                
            c.RouteTemplate = "api-docs/{documentName}/swagger.json";                 
        });          

        app.UseSwaggerUI(c =>
        {  
            //Include virtual directory if site is configured so
            c.SwaggerEndpoint(Configuration["Appsettings:VirtualDirectory"]+"api-docs/v1/swagger.json","Api v1");                
        });

 services.AddSwaggerGen(c =>
        {
 var xmlDocPath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath,"Api.xml");
            c.IncludeXmlComments(xmlDocPath);
            c.DescribeAllEnumsAsStrings();

具有上述配置

发展

"AppSettings": {
"VirtualDirectory": "/"

}

分期

"AppSettings": {
"VirtualDirectory": "/Api/"

}

启动计算机上UI的终点,暂存时间为ON

http://localhost:5001/api-docs/v1/swagger.json

但是在登台服务器上也是一样的

http://xxxx:5002/swagger/Api/api-docs/v1/swagger.json

而不是(应该是什么)

http://xxxx:5002/Api/api-docs/v1/swagger.json

解决方法

这个问题与环境变量更相关. Swagger支持虚拟目录,然后配置应如下所示.请注意,虚拟目录不会影响UI端点.
app.UseSwagger(c =>
            {
                //Change the path of the end point,should also update UI middle ware for this change                
                c.RouteTemplate = "api-docs/{documentName}/swagger.json";
            });
 app.UseSwaggerUI(c =>
            {
                //Include virtual directory if site is configured so
                c.RoutePrefix = "api-docs";
                c.SwaggerEndpoint("v1/swagger.json","Api v1");
            });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读