gpt4 book ai didi

asp.net-web-api - 无法运行 Swagger UI

转载 作者:行者123 更新时间:2023-12-01 22:46:45 31 4
gpt4 key购买 nike

我有一个 .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 基本 URL 是:http://localhost:88/因此,当我尝试打开此 URL 时,我得到一个 404:http://localhost:88/swagger/ui

我使用的是 NetCore 1.0.1,在 project.json 中,我用这一行来导入 Swagger: "Swashbuckle.AspNetCore": "1.0.0"

有什么帮助吗?谢谢

最佳答案

您在浏览器中输入了错误的 URL。使用 Swagger 1.0.0 RTM,默认 url 从 http://localhost:88/swagger/ui 更改为至 http://localhost:88/swagger

关于asp.net-web-api - 无法运行 Swagger UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44871372/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com