private void HandleAjaxRequest()
        {
            var errors = new List <string>();

            var username   = Request.Form["UserName"];
            var password   = Request.Form["Password"];
            var rememberMe = String.Equals(Request.Form["RememberMe"], "on");
            var returnUrl  = Request.QueryString["ReturnUrl"];
            var redirect   = VirtualPathUtility.ToAbsolute("~/");

            Response.ContentType = "application/json";

            AccountHelpers.Require(errors, username, "The User name field is required");
            AccountHelpers.Require(errors, password, "The Password field is required");

            if (errors.Count == 0)
            {
                if (Membership.ValidateUser(username, password))
                {
                    FormsAuthentication.SetAuthCookie(username, rememberMe);
                    if (IsLocalUrl(returnUrl))
                    {
                        redirect = returnUrl;
                    }
                }
                else
                {
                    errors.Add("The user name or password provided is incorrect.");
                }
            }

            AccountHelpers.WriteJsonResponse(Response, errors, redirect);
        }
        private void HandleAjaxRequest()
        {
            var errors = new List <string>();

            var username        = Request.Form["UserName"];
            var password        = Request.Form["Password"];
            var confirmPassword = Request.Form["ConfirmPassword"];
            var email           = Request.Form["Email"];

            Response.ContentType = "application/json";

            AccountHelpers.Require(errors, username, "The User name field is required");
            AccountHelpers.Require(errors, password, "The Password field is required");
            AccountHelpers.Require(errors, confirmPassword, "The Confirm password field is required");
            AccountHelpers.Require(errors, email, "The Email address field is required");
            if (!String.Equals(password, confirmPassword, StringComparison.Ordinal))
            {
                errors.Add("The Password and Confirmation password do not match.");
            }

            if (errors.Count == 0)
            {
                MembershipCreateStatus status;
                Membership.CreateUser(username, password, email, passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out status);

                if (status == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(username, createPersistentCookie: false);
                }
                else
                {
                    errors.Add(ErrorCodeToString(status));
                }
            }

            AccountHelpers.WriteJsonResponse(Response, errors);
        }