I am facing "Http failure response" for put method, when i try to update my userdetails on userdetails page of my angular 2 application. Can any one provide me idea to fix the following error.
Error:- Message: "The requested resource does not support http method 'PUT'." message: "Http failure response for http://localhost/TestWebAPI/api/UserDetails: 405 Method Not Allowed"
userdetails.component.ts
onUpdateUserClick(index)
{
this.objuserservice.UpdateUser(this.UpdateUser).subscribe
(
(response) => {
this.UpdateUser = response;
this.userslist[this.updateIndex].email = this.UpdateUser.email;
this.userslist[this.updateIndex].personname = this.UpdateUser.personname;
this.userslist[this.updateIndex].mobile = this.UpdateUser.mobile;
this.userslist[this.updateIndex].dateofbirth = this.UpdateUser.dateofbirth;
this.userslist[this.updateIndex].monthofbirth = this.UpdateUser.monthofbirth;this.userslist[this.updateIndex].yearofbirth=this.UpdateUser.yearofbirth;
this.userslist[this.updateIndex].gender = this.UpdateUser.gender;
this.userslist[this.updateIndex].country = this.UpdateUser.country;
},
(error)=>{
});
}
users.service.ts
UpdateUser(userobj:User):Observable<User>
{
return this.http.put<User>(`/TestWebAPI/api/UserDetails`,userobj,responseType:"json"});
}
Here is my asp.netwebapi(TestWebAPI) project code,
public void Put(int id, [FromBody]user objuser)
{
dbentity.Entry(objuser).State = System.Data.Entity.EntityState.Modified;
dbentity.SaveChanges();
}
id? You could try to modify your method to be justpublic void Put([FromBody]user objuser)and put a breakpoint in the method just for testing, to see if that request would be correctly handled.idin the URL, from Angular, likethis.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});.