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

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

问题描述

Swagger UI端点在暂存阶段与开发人员不同(不包括域名)

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

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

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