Search code examples
c#angularjserror-messages-for

Angularjs function returning to many redirects


I am rather new to AngularJS and I have a function that is returning "Too many automatic redirections were attempted. I am running Ionic and AngularJS on the application side and on the server side I am running C#. I did not create the C# server side, so I do not know where to begin looking for the mistake. My question is there a specific thing I should be looking for? What would cause this error to show? and would this be on the server side or the client side?

var forgotPassword = ForgotPassword.save({email:resp}).$promise.then(
        function Success(sucresp) {
          console.log("This returned with: " + sucresp)
          if (sucresp.ForgotPasswordResult.IsSuccess == true) {
              $ionicPopup.alert({
                    title: "Password Changed",
                    template: sucresp.ForgotPasswordResult.ErrorMessage
                });
          } else {
              $ionicPopup.alert({
                    title: "Password Was Not Changed",
                    template: sucresp.ForgotPasswordResult.ErrorMessage
                });
          }
        },
        function Failed(erresp){

          console.log("This failed like your life, now start crying: " + erresp)
          $ionicPopup.alert({
                    title: "Error Messge",
                    template: erresp
                });
        }
      ); 

and the server side is.

public ForgotPasswordResponse ForgotPassword(string email)
    {
        ForgotPasswordResponse resp = new ForgotPasswordResponse();
        resp.IsSuccess = false;

        string emailAddress = email;

        System.Security.Cryptography.RandomNumberGenerator randGen = System.Security.Cryptography.RandomNumberGenerator.Create();
        byte[] bytes = new byte[6];
        randGen.GetNonZeroBytes(bytes);
        string newPassword = Convert.ToBase64String(bytes);
        newPassword = Regex.Replace(newPassword, "[^a-zA-Z0-9]+", "", RegexOptions.Compiled);

        bool resetPasswordResult = false;
        try
        {
            string emailBody = string.Format(@"Your ****.com password has been reset.

The new password is {0}

Go to https://****.com/Login/login.aspx to login to the web site.

It is recommended that you change your password as soon as possible.

This message was sent from an automated system.  Please do not reply to it.", newPassword);

            Email.SendAmazonSES(emailAddress, "password reset", emailBody);
            resetPasswordResult = ResetPassword(emailAddress, newPassword);

            if (resetPasswordResult == false)
            {
                throw new Exception("The user account does not exist.");
            }

            resp.IsSuccess = true;
            resp.ErrorMessage = "Your password has been reset.  Check your email for the new password.";
        }
        catch (Exception ex)
        {
            resp.IsSuccess = false;
            resp.ErrorMessage = ex.Message;
            return resp;
        }

        return resp;
    }

Solution

  • The reason why it was doing this was the one page was going from one page to another then back to the 1st page. It was redirecting it from page to page and eventually timing out.