在ASP .NET CORE/MVC 6应用程序中设置Swagger时出现500错误 [英] 500 Error when setting up Swagger in asp .net CORE / MVC 6 app

查看:1033
本文介绍了在ASP .NET CORE/MVC 6应用程序中设置Swagger时出现500错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新的asp .net CORE/MVC 6项目中设置基本的swagger API文档,并从swagger UI接收到500错误: 500 : http://localhost:4405/swagger/v1/swagger.json

I'm trying to setup a basic swagger API doc in a new asp .net CORE / MVC 6 project and receiving a 500 error from the swagger UI: 500 : http://localhost:4405/swagger/v1/swagger.json

我的启动类中包含以下代码:

My startup class has the following code in it:

using Swashbuckle.SwaggerGen;
using Swashbuckle.SwaggerGen.XmlComments;
using Swashbuckle.Application;
....
public void ConfigureServices(IServiceCollection services)
{
  ...
  services.AddSwaggerGen();
  services.ConfigureSwaggerDocument(options =>
  {
    options.SingleApiVersion(new Info
    {
        Version = "v1",
        Title = "Blog Test Api",
        Description = "A test API for this blogpost"
    });
  });
}

,然后在配置"下:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
....
  app.UseSwaggerGen();
  app.UseSwaggerUi();
....
}

当我构建并运行该项目时,当我转到swagger/UI/index.html时,将显示UI,但是会显示上述500错误.当我转到swagger/v1/swagger.json链接时,控制台显示以下500错误: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

When i build and run the project, the UI will come up when i go to swagger/UI/index.html, but the 500 error above is displayed. When i go to the swagger/v1/swagger.json link, console gives the following 500 error: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

有什么办法可以找出500的根本原因,还是可以大张旗鼓地启用任何其他调试功能,以弄清楚为什么它会引发此错误?根据我看过的一些教程,基本实现只需要我在启动时拥有的内容即可.请让我知道是否可以提供其他信息.

Is there any way i can figure out the root cause of the 500 or enable any additional debug in swagger to figure out why it's throwing this error? Based on some of the tutorials i've looked at, only what i have in startup is required for a base implementation. Please let me know if i can provide any additional information.

这是针对rc1的,可能与当前发布的新netcore 1.0(2016年6月29日)不相关

this is for rc1, and may not be relevant to the new netcore 1.0 currently out (6/29/2016)

推荐答案

最初我也遇到500错误.在堆栈跟踪的深处它说: System.NotSupportedException:路径' api/hotels'的无界HTTP动词.您是否缺少HttpMethodAttribute?

Initially I got a 500 error too. Deep down in the stacktrace it said: System.NotSupportedException: Unbounded HTTP verbs for path 'api/hotels'. Are you missing an HttpMethodAttribute?

原来,我缺少一种api方法的HttpGet属性:

It turned out I was missing a HttpGet attribute for one of my api methods:

[Microsoft.AspNetCore.Mvc.HttpGet]

这篇关于在ASP .NET CORE/MVC 6应用程序中设置Swagger时出现500错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆