2015-01-28 5 views
2

나는 스타터 사이트 템플릿과 함께 제공되는 사용자 관리를 기반으로 내 사이트를 구축했습니다. 이것은 사용 사례에 따라 약간 수정해야한다는 점을 제외하면 매우 잘 작동합니다. 설명해 드리겠습니다 :Webmatrix 스타터 사이트 - 새로운 사용자는 이메일 확인이 필요합니다.

현재 새 사용자가 등록하면 데이터베이스에 사용자가 만들어 지지만 "WebSecurity.RequireAuthenticatedUser();"를 사용하여 보안 설정된 페이지에는 사용자가 액세스 할 수 없습니다. 열 때까지 확인 이메일을 클릭하십시오 ....

이메일을 확인하기 전에 사용자가 내 사이트의 특정 부분에 액세스 할 수 있도록 허용 하시겠습니까?

WebSecurity.RequireAuthenticatedUser()와 다른 방법을 사용해야합니까? 사용자 생성시 "requireEmailConfirmation"스위치를 제거해야합니까 ??

현재는 다음과 같습니다 그들은이이은에가는 사람이 볼 수있는 페이지 가기

@{ 
    if (!WebSecurity.IsAuthenticated) { 
     Response.Redirect("~/Account/Login?returnUrl=" 
      + "~/AllRaces.cshtml"); 
    } 

    Layout = "~/_SiteLayout.cshtml"; 
    Page.Title = "Upcoming"; 
} 

에 간다 를 사용하여 등록해야합니다 페이지

   try { 
       bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty(); 
       var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation); 
       if (requireEmailConfirmation) { 
        var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped); 
        var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/owner/confirm?confirmationCode=" + HttpUtility.UrlEncode(token)); 

        var details = "X-MC-MergeVars: {\"FIRSTNAME\": \"" + firstname + "\", \"LASTNAME\": \"" + lastname + "\", \"CONFIRMADDRESS\": \"" + confirmationUrl + "\"}"; 
        var header = new[]{"X-MC-Template:registertemplate", "Reply-To:[email protected]", details}; 

        WebMail.Send(
         to: email, 
         subject: "Please confirm your account", 
         body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "\">" + confirmationUrl + "</a> to activate your account.", 
         additionalHeaders: header 
        ); 
       } 

       if (requireEmailConfirmation) { 
        // Thank the user for registering and let them know an email is on its way 
        Response.Redirect("~/owner/thanks"); 
       } else { 
        // Navigate back to the homepage and exit 
        WebSecurity.Login(email, password); 

        Response.Redirect("~/"); 
       } 
      } catch (System.Web.Security.MembershipCreateUserException e) { 
       ModelState.AddFormError(e.Message); 
      } 
+0

사용자가 어떻게 요 페이지에 액세스하지 못하게합니까? 그들이 등록을 확인하기 전에 액세스 할 수 있기를 원하십니까? –

+0

안녕 마이크, 현재 내 "소유자"페이지는 WebSecurity.RequireAuthenticatedUser()를 사용하여 보호됩니다. 방법. 그러나 테스트를 통해 사용자가 이메일을 통해 계정을 확인한 후에 만 ​​작동합니다. – Gavin5511

+0

내가 원하는 것은 이메일을 확인하기를 기다리는 대신 확인 전에 특정 페이지에 계속 액세스 할 수 있습니다. 문제는 WebSecurity.CurrentUserId를 사용하여이 페이지에서 SQL 호출을해야한다는 것입니다. 방법, 내가 할 수있는 한 번 사용자가 오른쪽에 로그인되어 있습니까? – Gavin5511

답변

0

상단

@{ 
    Layout = "~/_SiteLayout.cshtml"; 
    Page.Title = "Contact"; 
}