Http failure response for put method in angular 2 with asp.net webapi
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();
}
angular asp.net-web-api
add a comment |
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();
}
angular asp.net-web-api
Maybe it's a problem that you are not passing thatid
? 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.
– Dan Dumitru
Nov 23 '18 at 11:29
On second thought, if you have the default routes in Web API, maybe you should pass thatid
in the URL, from Angular, likethis.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.
– Dan Dumitru
Nov 23 '18 at 11:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01
add a comment |
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();
}
angular asp.net-web-api
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();
}
angular asp.net-web-api
angular asp.net-web-api
edited Nov 25 '18 at 13:36
Dan Dumitru
4,74612641
4,74612641
asked Nov 23 '18 at 10:32
rajularajula
53
53
Maybe it's a problem that you are not passing thatid
? 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.
– Dan Dumitru
Nov 23 '18 at 11:29
On second thought, if you have the default routes in Web API, maybe you should pass thatid
in the URL, from Angular, likethis.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.
– Dan Dumitru
Nov 23 '18 at 11:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01
add a comment |
Maybe it's a problem that you are not passing thatid
? 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.
– Dan Dumitru
Nov 23 '18 at 11:29
On second thought, if you have the default routes in Web API, maybe you should pass thatid
in the URL, from Angular, likethis.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.
– Dan Dumitru
Nov 23 '18 at 11:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01
Maybe it's a problem that you are not passing that
id
? You could try to modify your method to be just public void Put([FromBody]user objuser)
and put a breakpoint in the method just for testing, to see if that request would be correctly handled.– Dan Dumitru
Nov 23 '18 at 11:29
Maybe it's a problem that you are not passing that
id
? You could try to modify your method to be just public void Put([FromBody]user objuser)
and put a breakpoint in the method just for testing, to see if that request would be correctly handled.– Dan Dumitru
Nov 23 '18 at 11:29
On second thought, if you have the default routes in Web API, maybe you should pass that
id
in the URL, from Angular, like this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.– Dan Dumitru
Nov 23 '18 at 11:35
On second thought, if you have the default routes in Web API, maybe you should pass that
id
in the URL, from Angular, like this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.– Dan Dumitru
Nov 23 '18 at 11:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01
add a comment |
1 Answer
1
active
oldest
votes
If you have the default routes in Web API, you should pass that id
in the URL from Angular, like:
UpdateUser(userobj:User):Observable<User>
{
this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj,
responseType:"json"});
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445005%2fhttp-failure-response-for-put-method-in-angular-2-with-asp-net-webapi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have the default routes in Web API, you should pass that id
in the URL from Angular, like:
UpdateUser(userobj:User):Observable<User>
{
this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj,
responseType:"json"});
}
add a comment |
If you have the default routes in Web API, you should pass that id
in the URL from Angular, like:
UpdateUser(userobj:User):Observable<User>
{
this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj,
responseType:"json"});
}
add a comment |
If you have the default routes in Web API, you should pass that id
in the URL from Angular, like:
UpdateUser(userobj:User):Observable<User>
{
this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj,
responseType:"json"});
}
If you have the default routes in Web API, you should pass that id
in the URL from Angular, like:
UpdateUser(userobj:User):Observable<User>
{
this.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj,
responseType:"json"});
}
edited Nov 24 '18 at 9:46
answered Nov 24 '18 at 9:41
Dan DumitruDan Dumitru
4,74612641
4,74612641
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445005%2fhttp-failure-response-for-put-method-in-angular-2-with-asp-net-webapi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe it's a problem that you are not passing that
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.– Dan Dumitru
Nov 23 '18 at 11:29
On second thought, if you have the default routes in Web API, maybe you should pass that
id
in the URL, from Angular, likethis.http.put<User>("/TestWebAPI/api/UserDetails/" + userObj.Id, userobj, responseType:"json"});
.– Dan Dumitru
Nov 23 '18 at 11:35
Thanks Dan , it works
– rajula
Nov 24 '18 at 4:35
@rajula - Great, I've made an answer out of that comment, so it would be more visible, you can accept it if you want.
– Dan Dumitru
Nov 24 '18 at 9:44
yes, i accept it with happiness
– rajula
Nov 25 '18 at 12:01