나는 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())
여기서'HttpContext.Current.Session [ "Documents"]'를 설정합니까? – Igor
@Igor OP에서 내 편집을 봅니다. 감사. – gog