【发布时间】:2026-02-04 02:20:02
【问题描述】:
我在这里读了一个答案,他说:
静态对于应用程序域是唯一的,该应用程序域的所有用户将共享每个静态属性的相同值
但我现在很困惑,我为许多用户创建了一个项目,他们当然会共享同一个域。
理解示例代码:
public static class ApplicationSession
{
private static readonly ICurrentSession Session;
static ApplicationSession()
{
if (HttpContext.Current == null)
Session = new ThreadedCurrentSession();
else
{
Session = new WebCurrentSession();
}
}
public static T GetObject<T>(string key) where T : class
{
return (T)Session.GetItem(key);
}
public static void SetObject<T>(string key, T t) where T : class
{
Session.SetItem(key, t);
}
}
public static SysUser CurrentUser
{
get
{
var currentusr = ApplicationSession.GetObject<SysUser>("CurrentUser");
if (currentusr == null)
{
currentusr = SysUserAccessor.CreateEmptyUser();
currentusr.SetRoles(new List<FrUserRole>());
ApplicationSession.SetObject("CurrentUser", currentusr);
}
return currentusr;
}
}
SysUser 是我的模型,它拖动我的用户和我的用户角色...
如果他们进行身份验证,他们现在是否会共享相同的 SysUser 模型。或者请提供其他帮助 :)
【问题讨论】:
标签: asp.net session static session-variables static-variables