Http failure response for put method in angular 2 with asp.net webapi












0















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();
}









share|improve this question

























  • 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











  • 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
















0















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();
}









share|improve this question

























  • 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











  • 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














0












0








0


0






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();
}









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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











  • 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











  • 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











  • @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












1 Answer
1






active

oldest

votes


















1














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"});
}





share|improve this answer

























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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"});
    }





    share|improve this answer






























      1














      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"});
      }





      share|improve this answer




























        1












        1








        1







        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"});
        }





        share|improve this answer















        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"});
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 24 '18 at 9:46

























        answered Nov 24 '18 at 9:41









        Dan DumitruDan Dumitru

        4,74612641




        4,74612641
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin