c# - System.InvalidOperationException:没有路由与提供的值匹配
问题描述
我正在尝试通过 post 方法执行 API call-in.NET 5.0,但得到 System.InvalidOperationException: No route 与提供的值匹配。你能帮我做同样的事情吗?
我的代码
[Route("api/[controller]")]
[ApiController]
public class CommonController : ControllerBase
{
private readonly IConfiguration _configuration;
private readonly ILanguages _Languages;
public CommonController(ILanguages Languages, IConfiguration configuration)
{
_Languages = Languages;
_configuration = configuration;
}
[HttpGet, Route("GetLanguages")]
public Languages GetLanguages()
{
try
{
return _Languages.GetLanguages();
}
catch (Exception)
{
throw;
}
}
}
解决方案
将方法转换为异步时出现此错误。更新 Startup.cs 中的 AddControllers 函数对我有用。
此处的解决方案:ASP.NET CORE,Web API:没有路由与提供的值匹配
问题原因:在运行时,异步后缀被删除。
services.AddControllers(
options => {
options.SuppressAsyncSuffixInActionNames = false;
}
);
推荐阅读
- php - 一个月后如何自动删除文件?
- versioning - sphinx-versioning 显示分支而不是版本号
- r - 在 R 中外部连接后,如何从特定时间段复制值以替换 NA?
- node.js - Node.js process.versions.node 未定义
- c++ - 在字符串中查找中间词
- flutter - 如何在颤动中更改按钮上的文本
- rust - 如何存储可以转换为可以多次使用的迭代器的迭代器或对象的异构列表?
- java - 在不修改原代码的情况下,用Maven替换JAVA代码中的常量
- javascript - 如何使用子进程从父目录运行 .class 文件?
- jenkins - 无法在 Jenkins 管道的后台启动 Jmeter-Server。获取 ConnectException