다른 답변보다 명확한 부분을 추가하여 혼란에 도움이되지 않는 문제에 대해 설명하지 않기를 바랍니다.
첫번째로, 당신의 사용자 지정 공급자를 구현하는 것을 당신이 이미 완료했습니다, 그래서 조금 코드를 던질거야 여기에 더 세부 사항으로 가지 않을 것이다 소리에서 :
using System.Web.Security;
public class MyCustomMembershipProvider : MembershipProvider
{
public override bool ValidateUser(string username, string password)
{
if (username.Equals("BenAlabaster") && password.Equals("Elephant"))
return true;
return false;
}
/* Override all the other methods required to extend MembershipProvider */
}
<membership defaultProvider="MyCustomMembershipProvider">
<providers>
<clear />
<add name="MyCustomMembershipProvider"
type="MyNamespace.MyCustomMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="10"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="/" />
</providers>
</membership>
난 당신이 지나친 것 같아 다음 비트, 실제 끼워 팔기에 웹 응용 프로그램 :
는 그런 다음베이스는 MembershipProvider를 구성 속성을 채우기 위해 확인하는 당신의 Web.config에 공급자를 구성 . WebForms 앱에서는 나머지를 스스로 코딩해야하지만 MVC 프레임 워크는 나머지 작업을 수행해야합니다. 액션 메소드에 [Authorize] 속성을 추가하면 프레임 워크가 로그인하고 로그인 페이지로 리디렉션하지 않은 경우 즉, Web.config의 구성이고에 사용자를 기록합니다 무엇 때문에 로그인 페이지가 사용자 지정 공급자를 찾을 수 당신은하여 사용자 객체 참조하여 컨트롤러에서 로그인 한 사용자에 대한 정보에 액세스 할 수 있습니다.
public class WhateverController : Controller
{
[Authorize]
public ActionResult WhateverAction()
{
ViewData["LoggedInAs"] = string.Format("You are logged in as {0}.", User.Identity.Name);
Return View();
}
}
을
이 작업을 수행하려면 사용자가 로그인되어 있고 페이지에 표시 될 Whatever/WhateverAction.aspx보기에 사용자 정보를 제공해야합니다.
좋아요, 그건 의미가 있습니다 - 정리 해줘서 고마워요. 나는 단지 두 개와 두 개를 맞추지 않고 있었다. 나는 여전히 WebForms 프레임에 머물러 있고 MVC가 나를 위해 그것을 할 때 그리고 내가 직접 처리해야 할 때를 알아 내지 못했다. – BobTheBuilder