我已經在登錄時創建會話,在該會話中我已經放置了用戶對象。更新會話值
public sealed class MyContext
{
[ThreadStatic]
private static MyContext staticContext = null;
public HttpContext Context
{
get
{
return HttpContext.Current;
}
}
private MyContext()
{
}
public static MyContext Current
{
get
{
MyContext myContext = null;
HttpContext context = HttpContext.Current;
if (context != null)
{
//it in the Items collection (a per request store)
if (context.Items.Contains("CONTEXT_KEY"))
myContext = context.Items["CONTEXT_KEY"] as MyContext;
else
{
myContext = new MyContext();
myContext.Context.Items["CONTEXT_KEY"] = myContext;
}
}
else if (staticContext != null)
{
myContext = staticContext;
}
else
{
//create a new instance of static context as there is no web request
staticContext = new MyContext();
myContext = staticContext;
}
return myContext;
}
}
public MyUser User
{
get
{
MyUser user = null;
if (Current.Context.Session["LoggedInUser"] != null)
user = (MyUser)Current.Context.Session["LoggedInUser"];
else
{
user = UserDetail.GetUser(HttpContext.Current.User.Identity.Name);
if (user == null)
{
//if there is no userID, create anonymous user
user = new MyUser();
user.IsAnonymous = true;
user.UserID = 0;
}
//cache in session
Current.Context.Session["User"] = user;
}
return user;
}
set
{
Current.Context.Session["User"] = value;
}
}
}//end class
現在我使用這樣的背景下整個應用程序,我在一個案件中面臨的問題,如果用戶登錄和同時管理員停用該用戶,我無法停止用戶活動,這是因爲用戶的信息正在開會。 所以請建議我在管理員停用該用戶時如何更新特定用戶的信息。
@其他:我覺得一樣,但沒有任何想法如何更新特定用戶的信息。 – Vijjendra 2013-03-27 18:58:43