虚拟目录中的 IIS 站点 Swagger UI 端点站点、目录中、UI、IIS

由网友(初璃兮微°半心人)分享简介:Swagger UI 端点与 staging 中的 dev 不同(不包括域名)Swagger UI end point is not same as dev in staging ( excluding domain names)IIS 配置public void Configure(IApplicationBui...

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");
            });
阅读全文

相关推荐

最新文章