2013-05-01 2 views
1

나는 ASP.NET MVC4와 함께 프로젝트를 진행하고 있으며 다른 페이지에서 ID, 이름 등의 현재 사용자 정보를 사용하여 로그인해야합니다.인증 + 세션 사용자 ASP.NET 유지하기

[HttpPost] 
    public ActionResult Auth(string login, string password) 
    { 
     // Customer c = null; 
     Customer cus = (from e in db.Customers where e.Login == login && e.Password == password select e).SingleOrDefault(); 
     if (cus != null) 
     { 


      //String s = User.Identity.Name; 
      return RedirectToAction("Index"); 
     } 
     else return RedirectToAction("Error"); 
    } 

나는 세션 코드가 필요하다고 생각합니다. 아무도 도와 줄 수 없습니까? ??

+4

빈 프로젝트와 함께 제공된 계정 컨트롤러에서 생성 된 코드가 어떻게 수행되었는지 확인할 수 있습니다. 그것은'FormsAuthentication' 클래스를 사용합니다. – codingbiz

답변

0

MVC4에서는 knockoutjs와 breeze를 사용할 수 있습니다.이 방법을 사용하면 컨텍스트 형식으로 다른보기에서 다른보기로 값을 전달할 수 있으며보기 활성화시 해당 값을 검색 할 수 있습니다. 그것이 내가 체크 Session 지난 시간에 민감한 사용자 정보를 저장하는 데 좋은 생각이 아니다 말했다

Customer cus = (from e in db.Customers where e.Login == login && e.Password == password select e).SingleOrDefault(); 
    if (cus != null) 
    { 
     // the boolean is for creating a persistent cookie 
     // also after this point User.Identity.Name should be == login 
     FormsAuthentication.SetAuthCookie(login, true); 

     // store more info in session and access it in other places 
     Session["Customer"] = cus; 

     //String s = User.Identity.Name; 
     return RedirectToAction("Index"); 
    } 

:

난 당신이 이런 일을 할 수있을 것 같아요 바람

0

link을 참조하시기 바랍니다 ASP.NET 세션 도용은 여전히 ​​문제였습니다. 필요한 것만 저장하십시오. 희망이 도움이됩니다.