![](/img/trans.png)
[英]Azure Cosmos DB - StartIndex cannot be less than zero. (Parameter 'startIndex')
[英]How to specify the route Groups?startIndex={startIndex}&count={count} for azure functions
如何以以下格式指定 azure function 的路由
Groups?startIndex={startIndex}&count={count}
由于Microsoft Q&A中已经讨论过相同的问题,感谢Mayank Bargali - 发布您的答案以帮助其他社区成员:
您只能定义
string
值,因为 Route 属性是字符串类型。 根据您的要求,您可以如下定义路由并获取查询参数,您可以利用HttpRequest
objectQuery
参数。 有关路由参数和查询字符串的更多详细信息,请参阅此文档。Route = "tc2/users/Groups/{id:int?}"
我使用以下 C# 代码进行测试。
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "tc2/users/Groups/{id:int?}")] HttpRequest req, int? id,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
int startIndex, count;
if (.String.IsNullOrEmpty(req.Query["startIndex"]))
startIndex = int.Parse(req.Query["startIndex"]);
if (.String.IsNullOrEmpty(req.Query["count"]))
count = int.Parse(req.Query["count"]);
return new OkObjectResult("Ok");
}
注:以上内容仅供参考,请根据业务需要进行更新,并在转换查询参数时处理异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.