Ambiguous HTTP method Actions require an explicit HttpMethod binding for Swagger 2.0 异常

 

网上看了很多关于此异常的解决方案,但是大多数都是不能用的,今天把正确的解决方案记录下来,以帮助需要的人

问题:有些接口没有设置HttpPost或HttpGet,非接口设置访问权限为private,控制台可以看到报错位置为UserController.Info

 

 

接口错误示例:
public object Get()
{
    MongoDbContext dbContext = new MongoDbContext();
    return new {
        API = true,
        Database = dbContext.Status()
    };
}

接口正确示例:

[HttpGet]
public object Get()
{
    MongoDbContext dbContext = new MongoDbContext();
    return new {
        API = true,
        Database = dbContext.Status()
    };
}

非接口(方法)示例:(访问权限设置成private,protected)

        private DateTime SecondsToDateTime(long seconds)
        {
            var d1970 = new DateTime(1970, 1, 1);
            DateTime now = new DateTime(d1970.Ticks + seconds * 10000);
            ///零时区
            return TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);
        }

参考

https://stackoverflow.com/questions/47822177/swagger-net-core-api-ambiguous-http-action-debugging

posted @ 2019-12-09 20:31  liliyou  阅读(315)  评论(0编辑  收藏  举报