C# 当前会话工作异常
我对HttpContext.Current.Session[“someSession”]有疑问 在我的网站中,我有一个空的网格,用户可以在网格的编辑模式下添加一些行。当用户插入新行时,我将其存储在会话中,因此我有以下类:C# 当前会话工作异常,c#,asp.net,asp.net-mvc,session,C#,Asp.net,Asp.net Mvc,Session,我对HttpContext.Current.Session[“someSession”]有疑问 在我的网站中,我有一个空的网格,用户可以在网格的编辑模式下添加一些行。当用户插入新行时,我将其存储在会话中,因此我有以下类: public static class DocumentSessionRepository { public static IList<DocumentModel> AllDocuments() { return (IList<
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;
}
}
查看在此会话中绑定网格的位置
@(Html.Telerik()
.Grid<DocumentModel>()
.BindTo((List<DocumentModel>)DocumentSessionRepository.AllDocuments())
@(Html.Telerik()
.Grid()
.BindTo((列表)DocumentSessionRepository.AllDocuments())
假设问题出现在IList
实例中。如果此实例为所有用户共享,则会话是否特定于用户并不重要。看起来所有会话都共享同一个实例。请检查类实例化,例如,如果该类在静态字段中实例化,并且该字段存储在会话中,则所有用户都将我也有这个例子
我100%确定
Current.Session
工作正常。您在哪里设置HttpContext.Current.Session[“文档”]
?@I或者查看我在OP上的编辑。谢谢。
@(Html.Telerik()
.Grid<DocumentModel>()
.BindTo((List<DocumentModel>)DocumentSessionRepository.AllDocuments())