C# 使用属性路由为.NET Core 2.0中的API接受多个参数

C# 使用属性路由为.NET Core 2.0中的API接受多个参数,c#,asp.net-core,asp.net-core-webapi,C#,Asp.net Core,Asp.net Core Webapi,我有一个传入的GET请求,如下所示: https://localhost:44329/api/scoInfo?activityId=1&studentId=1&timestamp=1527357844844 如何在ASP.net-core中创建接受此请求的端点 我尝试了以下不同的版本,但没有任何效果: [HttpGet("{activityId: int}/{studentid: int}/{timestamp: int}")] [Route("api/ScoInfo/{act

我有一个传入的GET请求,如下所示:

https://localhost:44329/api/scoInfo?activityId=1&studentId=1&timestamp=1527357844844
如何在ASP.net-core中创建接受此请求的端点

我尝试了以下不同的版本,但没有任何效果:

[HttpGet("{activityId: int}/{studentid: int}/{timestamp: int}")]
[Route("api/ScoInfo/{activityId}/{studentid}/{timestamp}")]

查询参数不是路由路径的一部分。 其路线为“api/scoinfo”。然后,处理方法将使用[FromUri]修饰参数,该参数将映射到查询参数中的值

[Route("api/scoinfo")]
public HttpResponseMessage GetScoInfo([FromUri]int activityId, int studentId, int timeStamp)

使用
[FromQuery]
指定要应用的确切绑定源

//GET api/scoInfo?activityId=1&studentId=1&timestamp=1527357844844
[HttpGet("api/scoinfo")] 
public async Task<IActionResult> GetLearningTask(
    [FromQuery]int activityId, 
    [FromQuery]int studentId, 
    [FromQuery]int timeStamp) {
    //...
}
//获取api/scoInfo?activityId=1&studentId=1×tamp=1527357844844
[HttpGet(“api/scoinfo”)]
公共异步任务GetLearningTask(
[FromQuery]int activityId,
[FromQuery]int studentId,
[FromQuery]int时间戳){
//...
}
MVC将尝试按名称将请求数据绑定到操作参数。MVC将使用参数名及其公共可设置属性的名称查找每个参数的值

进一步参考

HKEY\u CLASSES\u ROOT\\shell\open\command中注册

使用(默认)for command=
“”“%1”

类似于
yourapp

这意味着在Windows中(通常从浏览器导航)有一个URL,如
yourapp:

启动位于
的应用程序

查看命令行,整个
yourapp:
通过注册表项中的
“%1”
传递给已启动的应用程序

缺点是要在注册表的该部分设置
,需要提升访问权限

UAP应用程序有更好的方法,因此这更适用于遗留应用程序(WPF、WinForms等)


HTH

我相信在.Net Core 2.0中没有使用FromURI和HttpResponseMessage消息-这就是我尝试的地方-但这仍然不起作用:
[HttpGet(“api/scoinfo/{activityId}/{studentId}/{timestamp}”)]
公共异步任务GetLearningTask([FromRoute]int activityId,[FromRoute]int studentId,[FromRoute]int时间戳)