【发布时间】:2023-03-20 08:58:01
【问题描述】:
我有一个 .NetCore Web API 项目。我正在尝试在上面使用 Swagger。 所有配置看起来都不错,但是当我运行我的项目时出现 404 错误,找不到页面。
这是我的代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(_config);
services.AddTransient<IRestHelper, RestHelper>();
// Add framework services.
services.AddApplicationInsightsTelemetry(_config);
services.AddMvc();
services.AddSwaggerGen(config =>
{
config.SwaggerDoc("v1", new Info { Title = "Slack Relay API", Version = "v1" });
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(_config.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseMvc();
app.UseSwagger(c =>
{
c.PreSerializeFilters.Add((swagger, httpReq) => swagger.Host = httpReq.Host.Value);
});
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1 Docs");
});
}
我的 Web API 基本网址是:http://localhost:88/ 因此,当我尝试打开此 URL 时,我得到一个 404:http://localhost:88/swagger/ui
我使用的是 NetCore 1.0.1,在 project.json 中我有这一行来导入 Swagger: "Swashbuckle.AspNetCore": "1.0.0"
有什么帮助吗? 谢谢
【问题讨论】:
标签: asp.net-web-api asp.net-core swagger swagger-ui asp.net-core-webapi