【发布时间】:2020-08-23 19:09:29
【问题描述】:
这是我的代码:
[HttpPost("{id}")]
[Route("DeleteUserProfile")]
public async Task<IActionResult> DeleteUserProfile(string id)
{
var user = await _userManager.FindByIdAsync(id);
_app.Users.Remove(user);
await _app.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
_app 是我的上下文。我删除 AspNetUsers 的方法对吗?当我在 Postman 中发布请求时,我得到 404 not found。请帮忙!我的网址是:http://localhost:57392/api/UserProfile/DeleteUserProfile/292207c9-e961-4073-b9b8-260e86f7cbe0。
【问题讨论】:
-
尝试将
HttpPost属性更改为HttpPost("DeleteUserProfile/{id}"),而不是Route。此外,当DELETE完全适合已完成的操作时,您可能不应该使用POST。这也意味着您不一定需要路径中的DeleteUserProfile。 -
您是否为“api/UserProfile”配置了RoutePrefix?
-
404,我做到了。我没有找到与提供的值匹配的路线。我必须检查那个错误,但我不知道为什么它不起作用,因为 getallusers() 方法像魅力一样工作......
-
它有效,我只需要更改 RedirectToAction() 中的参数,我的问题是路由,应该把 [HttpDelete("DeleteUserProfile/{id}")] 没有路由部分。谢谢大家: D
标签: c# asp.net .net asp.net-web-api