set RoutePrefix after swagger/ui/abp.swagger.js 404
@@set RoutePrefix after swagger/ui/abp.swagger.js 404
Swagger UI show 404 error when I deploy it on IIS
I have an asp.net core application with vue.js. I made web api. And when I'm debugging via localhost - everything is fine. Swagger UI is working, also as application. But when I deploy app to the IIS, Swagger don't work and show 404 error.
Here is swagger configuration in Startup.cs
services.AddSwaggerGen(config =>
{
var xmlFile = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
config.IncludeXmlComments(xmlPath);
});
app.UseSwagger(options =>
{
options.SerializeAsV2 = true;
options.RouteTemplate = "info/swagger/{documentname}/swagger.json";
});
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/info/swagger/v1/swagger.json", "v1");
options.RoutePrefix = "info/swagger";
});
What should I do? changing SwaggerEnpoint to "../info/swager....." don't help. I need to working asp .net core app and also swagger on IIS.
-
Have you made sure that the documentation file is copied to your deployed files?– Daniel KiptoonJan 22, 2022 at 17:37
-
@DanielKiptoon, yes, documentationfFile.xml in result directory.– Ilya VasilevskiyJan 22, 2022 at 18:02
1 Answer
The problem was in
app.UseSwagger(options =>
{
options.SerializeAsV2 = true;
});
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/applicationName/swagger/v1/swagger.json", "v1");
options.RoutePrefix = "info/swagger";
});
removing options.RouteTemplate and replace "info" on "appName" in options.SwaggerEndpoint helps me.
Swagger路由添加前缀 .Net Web Api
.Net Core / .Net 6 项目更改Swagger 路由:
定义一个路由前缀或从配置里读取
var routePrefix = AppSettingsExt.Get("route_prefix");
xml文档按常规方式引入
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = docTitle });
var files = new DirectoryInfo(AppContext.BaseDirectory).GetFiles("*.xml", SearchOption.AllDirectories);
foreach (var file in files)
{
c.IncludeXmlComments(file.FullName);
}
});
更改路由配置,UseSwagger 以及UseSwaggerUI 都需要修改
app.UseSwagger(c =>
{
c.RouteTemplate = routePrefix + "/swagger/{documentName}/swagger.json";
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint($"/{routePrefix}/swagger/v1/swagger.json", docTitle);
c.RoutePrefix = $"{routePrefix}/swagger";
});
————————————————
版权声明:本文为CSDN博主「山貓」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lynxkor/article/details/126524867