虚拟目录中的 IIS 站点 Swagger UI 端点 [英] IIS site within virtual directory Swagger UI end point

查看:17
本文介绍了虚拟目录中的 IIS 站点 Swagger UI 端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swagger UI 端点与 staging 中的 dev 不同(不包括域名)

Swagger UI end point is not same as dev in staging ( excluding domain names)

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 的终点,登台开启

The end point for UI on the dev machine with staging ON

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

但在登台服务器上是同一个

but the same one on the staging server

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

而不是(应该是什么)

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

推荐答案

这个问题与环境变量更相关.Swagger 确实支持虚拟目录,那么配置应该如下所示.请注意,虚拟目录不会影响 UI 端点.

The problem is more relevant to swagger than Environment variable. Swagger does support the virtual directory which then the configuration should look like below. Note that virtual directory doesn't affect the UI End point.

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

这篇关于虚拟目录中的 IIS 站点 Swagger UI 端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆