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

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

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....