Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;没有路线与提供的值相匹配;再一次_C#_Asp.net Core_.net Core_Asp.net Core Webapi - Fatal编程技术网

C# &引用;没有路线与提供的值相匹配;再一次

C# &引用;没有路线与提供的值相匹配;再一次,c#,asp.net-core,.net-core,asp.net-core-webapi,C#,Asp.net Core,.net Core,Asp.net Core Webapi,我正在使用ASP.NETCore3WebAPI。尝试使用createDataAction为创建的实体设置位置标头时,它因System.invalidoOperationException失败:没有路径与提供的值匹配。到目前为止我找到的所有答案都没有解决我的问题此问题应通过升级Microsoft.AspNetCore.Mvc.Versioning到4.2或更高版本来解决。请参阅GitHub上的。原因是在v4.2之前,API版本在URL生成期间未作为环境值处理,因此必须显式提供。换句话说,在v4.2

我正在使用ASP.NETCore3WebAPI。尝试使用
createDataAction
为创建的实体设置位置标头时,它因
System.invalidoOperationException失败:没有路径与提供的值匹配。
到目前为止我找到的所有答案都没有解决我的问题此问题应通过升级
Microsoft.AspNetCore.Mvc.Versioning
到4.2或更高版本来解决。请参阅GitHub上的。原因是在v4.2之前,API版本在URL生成期间未作为环境值处理,因此必须显式提供。换句话说,在v4.2之前,您必须编写以下内容:

[HttpPost(ReportsSegment)]
public ActionResult<ReportModel> CreateReport(ApiVersion apiVersion)
{
    // ...

    var entity = new ReportModel { ReportId = 2 };
    return CreatedAtAction(nameof(GetReport), new { reportId = entity.ReportId, version = apiVersion.ToString() }, entity);
}
[HttpPost(ReportsSegment)]
public ActionResult CreateReport(ApiVersion ApiVersion)
{
// ...
var entity=new ReportModel{ReportId=2};
返回createDataAction(nameof(GetReport),新的{reportId=entity.reportId,version=apiVersion.ToString()},entity);
}

谢谢!将Microsoft.AspNetCore.Mvc.Versioning更新为5.0.0版后,问题消失了