相关疑难解决方法(0)

静态会话类和多个用户

我正在构建一个类来在会话中存储用户ID和用户角色.我不确定当多个用户同时在网站上时这个类会如何表现.有没有人看到这个问题?

public static class SessionHandler
    {   
        //*** Session String Values ***********************

        private static string _userID = "UserID";
        private static string _userRole = "UserRole";

        //*** Sets and Gets **********************************************************

        public static string UserID
        {
            get
            {
                if (HttpContext.Current.Session[SessionHandler._userID] == null)
                { return string.Empty; }
                else
                { return HttpContext.Current.Session[SessionHandler._userID].ToString(); }
            }
            set
            { HttpContext.Current.Session[SessionHandler._userID] = value; }

        }
        public static string UserRole
        {
            get
            {
                if (HttpContext.Current.Session[SessionHandler._userRole] == null)
                { return string.Empty; }
                else
                { return HttpContext.Current.Session[SessionHandler._userRole].ToString(); }
            }
            set
            { HttpContext.Current.Session[SessionHandler._userRole] …
Run Code Online (Sandbox Code Playgroud)

c# asp.net session

7
推荐指数
1
解决办法
7618
查看次数

标签 统计

asp.net ×1

c# ×1

session ×1