2014-03-05 3 views
2

나는 HttpContext.Current.Session["someSession"]에 대해 의문의 여지가 있습니다.현재 세션이 이상하게 작동합니다

내 웹 사이트에서 사용자가 그리드의 편집 모드에서 일부 행을 추가 할 수있는 빈 그리드가 있습니다. 사용자가 새 행을 삽입 할 때, 나는 세션에 저장, 그래서 나는이 수업이 있습니다

public static class DocumentSessionRepository 
{ 
    public static IList<DocumentModel> AllDocuments() 
    { 
     return (IList<DocumentModel>)HttpContext.Current.Session["Documents"]; 
    } 

    public static void Insert(DocumentModel product) 
    { 
     AllDocuments().Add(product); 
    } 

    public static void Delete(Guid? idDocument) 
    { 
     var target = GetOneDocument(p => p.IDDocument == idDocument); 
     AllDocuments().Remove(target); 
    } 

    public static DocumentModel GetOneDocument(Func<DocumentModel, bool> id) 
    { 
     var one = AllDocuments().Where(id).FirstOrDefault(); 
     return one; 
    } 
} 

문제는 일부 사용자에 새로운 행을 삽입 그래서 만약 모든 사용자가 동일한 세션을 받고 있는지입니다 이 세션은 다른 사용자도 볼 수 있습니다.

이 정적 변수를 사용하여이 세션 변수를 관리하는 것이 좀 지저분하다고 생각합니다. 또는 나는 여기에서 무엇인가 놓치고있다.

누구나 도움이 될 수 있습니까?

편집 :이 세션 그리드를 결합 곳

public ActionResult InsertDocument(DocumentModel model) 
{ 
    //Some Code 
    DocumentSessionRepository.Insert(model); 
} 

보기 : 내가 설정하고 세션을 사용

장소.

@(Html.Telerik() 
     .Grid<DocumentModel>() 
     .BindTo((List<DocumentModel>)DocumentSessionRepository.AllDocuments()) 
+2

여기서'HttpContext.Current.Session [ "Documents"]'를 설정합니까? – Igor

+0

@Igor OP에서 내 편집을 봅니다. 감사. – gog

답변

2

IList<DocumentModel> 인스턴스에 문제가 있다고 가정합니다. 이 인스턴스가 모든 사용자에게 공유되는 경우 세션이 사용자별로 다르지 않습니다. 모든 세션이 같은 인스턴스를 공유하는 것처럼 보입니다. 예를 들어 클래스가 정적 필드에서 인스턴스화되고이 필드가 세션에 저장되는 경우 모든 사용자가이 인스턴스를 공유합니다.

저는 100 % 확신합니다. Current.Session이 정상적으로 작동합니다.

관련 문제