【发布时间】:2021-07-26 23:54:17
【问题描述】:
Swagger UI 端点与 staging 中的 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 的终点,登台开启
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
【问题讨论】:
-
展示你如何在开发机器上将环境设置为暂存,因为现在看起来你做错了。您是否将
ASPNETCORE_ENVIRONMENT变量设置为Staging或您使用的变量? -
没错,ASPNETCORE_ENVIRONMENT 变量。
标签: asp.net-core swagger swagger-ui