ASP.NET 멤버십은 허위로 승인되었지만 여전히 로그인을 허용합니다

StackOverflow https://stackoverflow.com/questions/1212503

  •  06-07-2019
  •  | 
  •  

문제

기본 계정 멤버십 제공 업체를 변경하여 설정하여 False로 승인했습니다.

    public MembershipCreateStatus CreateUser(string userName, string password, string email)
    {
        MembershipCreateStatus status;
        _provider.CreateUser(userName, password, email, null, null, false, null, out status);
        return status;
    }

그러나 로그인 페이지로 돌아가서 로그인 할 수 있습니다. 로그인에 실패하지 말고 승인되지 않았다고 말해야합니까?

편집하다:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Register(string userName, string email, string password, string confirmPassword, string address, string address2, string city, string state, string homePhone, string cellPhone, string company)
    {

        ViewData["PasswordLength"] = MembershipService.MinPasswordLength;

        if (ValidateRegistration(userName, email, password, confirmPassword))
        {

            // Attempt to register the user
            MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password, email);

            if (createStatus == MembershipCreateStatus.Success)
            {
                FormsAuth.SignIn(userName, false /* createPersistentCookie */);

                TempData["form"] = Request.Form;
                TempData["isActive"] = false;
                return RedirectToAction("Create", "Users");
            }
            else
            {
                ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus));
            }
        }

        // If we got this far, something failed, redisplay form
        return View();
    }
도움이 되었습니까?

해결책

(이 질문의 다른 사본이 문을 닫을 것 같습니다. 그래서 나는 여기에 내 대답을 복사했습니다)

httprequest.isauthenticated httpcontext.user.user.identity가 null이 아니고 Isauthenticated 속성이 true를 반환하면 true를 반환합니다.

현재의 정체성은 다음에 설정됩니다 FormsauthenticationModule, 그러나 회원 가입자와는 아무런 관련이 없습니다. 사실, 그것은 그것을 참조조차하지 않습니다. 인증 쿠키가 여전히 설정되어 있고 여전히 유효한지 확인하는 것입니다 (그대로 만료되지 않았습니다).

문제는 당신이 형태 인증 와 같은 방법 리디렉션 프롬 로그 인 페이지, 인증 쿠키를 설정하는 것입니다. 사용자가 승인 될 때까지 기다려야하는 경우 쿠키를 설정하지 않아야합니다.

업데이트

값이 없습니다 멤버십 크리 테이 타스 사용자가 생성되었지만 승인되지 않았 음을 지정하므로 코드가 FormsAuth.SignIn 실제로 사용자가 승인되었는지 확인하지 않고.

FormsAuth.SignIn 그냥 쿠키를 설정합니다. 사용자를 검증하지 않거나 멤버십 전문가와 관련이 없습니다. 승인이 비동기식이라면 (즉, 사람을 기다리고) formsauth.signin을 호출하여 사용자를 자동으로 로그인하지 마십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top