1

I'm trying to make a delete user route, but i can't get it to work.
Everything I find online is for .NET CORE.
I use ASP.NET MVC. So I ran routes.MapMvcAttributeRoutes() in RouteConfig.cs.
I than create a controller extending System.Web.Mvc.Controller. (Everything comes from the System.Web.Mvc namespace).

And I have the following method:

[HttpDelete, Route("user/{id:long}")]
public async Task<ActionResult> Destroy(long id)
{
    IAccountService accountService = new AccountService();

    bool success = await accountService.Delete(id);

    return Json(new AuthenticateDto());
}

Rearranging the attributes doesn't work (I'm new to attributes so idk if it even helps)
When I try to visit the url i receive a 404.

Anyone has a clue, why it does not work?

15
  • How do you test it? Webbrowsers only support get and post. What happens, when you replace [HttpDelete, Route("user/{id:long}")] whith [HttPost, Route("user/{id:long}")] and call /user/42? Commented May 29, 2020 at 0:06
  • I used postman to test it and used the folowing url: localhost:44378/user/5 Commented May 29, 2020 at 0:10
  • And did you selected delete in Postman? Commented May 29, 2020 at 0:26
  • yes, and If I change it with HttpPost it works just fine if I select Post Commented May 29, 2020 at 0:27
  • Do you have by chance a route http contriant? Commented May 29, 2020 at 0:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.