.net - core 2.1 webapi 并发删除
问题描述
目前我有一个可以删除的 webapi,但我需要确保只有在提供正确/当前版本的情况下才能删除它们。
我的模型是这样的:
public class Item {
public int Id {get;set;}
.. other properties ...
[Timestamp]
public byte[] Version {get;set;}
}
我目前有以下端点声明:
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
...
}
有人可以让我知道发送 byte[] 版本以便在删除之前进行检查的正确方法是什么?
为了实现这一点,我需要在删除端点声明(上图)中进行哪些更改?
提前致谢。
解决方案
您可以在请求的正文中传递您的时间戳。
public class DeleteItemRequest {
public byte[] Version {get;set;}
}
[HttpDelete("{id}")]
public IActionResult Delete(int id, [FromBody]DeleteItemRequest request)
{
...
}
推荐阅读
- c - 在 C 中使用 printf 时出现奇怪的符号
- excel - 使用 VBA 将特定列从工作簿复制到另一个
- algorithm - 为什么在递归矩阵遍历算法中返回 0 或 1?
- open3d - 重叠点 Open3d
- java - 构建 Spring Boot 本机应用程序(Eclipse + Maven + GraalVM + native-image 插件)失败(找不到 cl.exe)
- c# - 更改文件夹名称后未加载 Visual Studio 项目
- pandas - 仅在从工作代码构建 .exe 时:AttributeError: Can only use .dt accessor with datetimelike values
- html - rvest 电子邮件在具有复杂节点结构(html 节点)的页面上抓取
- javascript - 如何动态重命名 href="" 或内部链接/url?
- linker - ldd 对一个文件说“未找到”,而对另一个文件说“未找到”