I have this C# WebAPI 2 project:
[RoutePrefix("api/Account")]
public class AccountController : ApiController
{
....
[HttpDelete]
[Route("Delete")]
public async Task<IHttpActionResult> Delete(string password)
{
// retrieve the authorized user's username
// delete the authorized user using his password and username
}
....
}
My HTML form:
<form class="form-login span4 offset4 register-box" role="form">
<h2 class="form-login-heading">Delete your account</h2>
<h2 class="form-login-heading">Warning: this is permanent.</h2>
<input type="password" class="form-control" placeholder="Password" data-ng-model="deleteConfirmPassword" required>
<button class="btn btn-lg btn-info btn-block" type="submit" data-ng-click=" deleteAccount()">Delete</button>
</form>
And the controller that's used:
app.controller('accountController', [
'$scope', '$location', '$http', 'authService',
function($scope, location, $http, authService) {
$scope.deleteConfirmPassword = "";
$scope.deleteAccount = function() {
$http.delete(authService.serviceBase + 'api/account/Delete/', {
password: $scope.deleteConfirmPassword
}).success(function() {
authService.logOut();
}).
error(function(response) {
var errors = [];
for (var key in response.data.modelState) {
for (var i = 0; i < response.data.modelState[key].length; i++) {
errors.push(response.data.modelState[key][i]);
}
}
$scope.message = "Failed to delete your account due to:" + errors.join(' ');
});
};
}
]);
According to Firebug, the correct URL is called, however no parameters appear to be passed, and I'm getting a 404 error. What am I doing wrong in this code?