Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
I have an issue regarding web api for Change pwd it is working properly in fiddler but when i call it through ajax after submitting form it shows error as "HTTP Error 405.0 - Method Not Allowed"


What I have tried:

<pre>// Cotroller
[HttpPut]
        public HttpResponseMessage Put([FromUri]string oldPwd, [FromBody]Hotel_Login Hotel_Login)
        {
            using (Hotel_ShowEntities entities = new Hotel_ShowEntities())
            {
                try
                {
                    var entity = entities.Hotel_Login.FirstOrDefault(e => e.Password == oldPwd);
                    if (entity == null)
                    {
                        return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Customer with that Password=" + oldPwd.ToString() + "not found");

                    }
                    else
                    {
                        entity.Password = Hotel_Login.Password;
                        entities.SaveChanges();
                        return Request.CreateResponse(HttpStatusCode.OK, entity);
                    }
                }
                catch (Exception ex)
                {
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
                }
            }

        }

//Ajax call

 $(document).ready(function () {
                $("#btnSubmit").click(function () {
                    var CurrentPwd = $("#CurrPwd").val();
                    var Newpwd = $("#NewPwd").val();
                    console.log(Newpwd);
                    $.ajax({
                        type: "Put",
                        url: "http://localhost:16580/api/ChangeForgetPass/Put?oldPwd=" + CurrentPwd,
                        contentType: "application/json",
                        dataType: "json",
                        processData: true,
                        data: '{"Password":"' + Newpwd + '"}',                      
                        success: function (s) {
                            alert("Password Changed successfully");
                        },

                    });
                });


            });
Posted
Comments
F-ES Sitecore 15-Jun-17 6:16am    
Not sure querystring params work with PUT, you might need to put all your variables in the body\data.
Richard Deeming 15-Jun-17 11:13am    
So are you preventing two users from having the same password? Or just changing the password for all users who share the same password when one of them changes their password?

Either way, it's a massive security fail.

And talking of security fails, NEVER store passwords in plain text!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Member 12840365 18-Jun-17 4:16am    
I am trying to change a PASSWORD
the first user will enter the old password
the code will check whether that old password exists in the database
if that old password exists in database then it will change the new password enter by the user through HTML form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900