그래서 내 앱에서 인증을 구현하고 있습니다. xml 파일에 저장된 크레딧 (실제 프로젝트 아님).
다음은 코드입니다.
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
return RedirectToAction("Index", "Objects", new ObjectsModel(//user name));
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
public class CustomMembershipProvider : SimpleMembershipProvider
{
public override bool ValidateUser(string username, string password)
{
return true;
}
}
[Authorize]
public class ObjectsController : Controller
{
public ActionResult Index()
{
return View(new ObjectsModel(//get authentificated username));
}
}
두 가지 질문 :
내가 제대로하고 있는가? 아니면 WebSecurity 등을 사용해야합니다. 안전한 앱으로 충분합니까? 아니면 전체 직원에 대해 큰 오해가 있습니까?
사용자 지정 인증에는 UserContext , UserProfiles , IPrincipal 을 포함하는 멤버쉽 인프라의 일부로 많은 작업이 필요 합니다. model / dbcontext 대신 파일에 대해 사용자의 유효성을 검사하려는 경우 표준 WebSecurity 구현 으로 최소한의 노력으로 수행 할 수 있습니다 .
Visual Studio는 asp.net mvc 템플릿 프로젝트 멤버십 구현 준비 코드와 함께 제공됩니다. 모델과 맥락을 깊이 엿볼 수 있습니다.
자세한 내용 은 이 도움말 을 참조하세요.
ObjectsController (commented line)에서 UserName에 어떻게 로그인 할 수 있습니까?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다