⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcontext.cs

📁 ASP.NET简洁论坛源代码 这是一个简单的论坛
💻 CS
📖 第 1 页 / 共 2 页
字号:
            }
        }
        public int GroupId
        {
            get
            {
                if (groupId == 0)
                {
                    groupId = GetIntFromQueryString("GroupId", 0);
                }
                return groupId;
            }
            set
            {
                groupId = value;
            }
        }
        public string Subject
        {
            get
            {
                if (string.IsNullOrEmpty(subject))
                {
                    subject = QueryString["subject"];
                }
                return subject;
            }
            set
            {
                subject = value;
            }
        }
        public string Tags
        {
            get
            {
                if (string.IsNullOrEmpty(tags))
                {
                    tags = QueryString["tags"];
                }
                return tags;
            }
            set
            {
                tags = value;
            }
        }
        public int PageIndex
        {
            get
            {
                if (pageIndex == 0)
                {
                    pageIndex = GetIntFromQueryString("PageIndex", GetIntFromQueryString("p", 0));
                    if (pageIndex != 0)
                    {
                        pageIndex = pageIndex - 1;
                    }
                    else if (pageIndex < 0)
                    {
                        pageIndex = 0;
                    }
                }
                return pageIndex;
            }
            set
            {
                pageIndex = value;
            }
        }
        public int UserId
        {
            get
            {
                if (userId == 0)
                {
                    userId = GetIntFromQueryString("UserId", 0);
                }
                return userId;
            }
            set
            {
                userId = value;
            }
        }
        public string UserName
        {
            get
            {
                if (string.IsNullOrEmpty(userName))
                {
                    userName = QueryString["UserName"];
                }
                return userName;
            }
            set
            {
                userName = value;
            }
        }
        public int RoleId
        {
            get
            {
                if (roleId == 0)
                {
                    roleId = GetIntFromQueryString("roleId", 0);
                }
                return roleId;
            }
            set
            {
                roleId = value;
            }
        }

        public bool UserRealSize
        {
            get
            {
                try
                {
                    userRealSize = bool.Parse(QueryString["urs"]);
                }
                catch
                { }
                return userRealSize;
            }
            set
            {
                userRealSize = value;
            }
        }
        public string BackColor
        {
            get
            {
                if (string.IsNullOrEmpty(backColor))
                {
                    backColor = QueryString["bc"];
                }
                return backColor;
            }
            set
            {
                backColor = value;
            }
        }
        public string DefaultPicFileName
        {
            get
            {
                if (string.IsNullOrEmpty(defaultPicFileName))
                {
                    defaultPicFileName = QueryString["dpf"];
                }
                return defaultPicFileName;
            }
            set
            {
                defaultPicFileName = value;
            }
        }
        public string PictureFileName
        {
            get
            {
                if (string.IsNullOrEmpty(picFileName))
                {
                    picFileName = QueryString["pf"];
                }
                return picFileName;
            }
            set
            {
                picFileName = value;
            }
        }
        public int PictureWidth
        {
            get
            {
                if (picWidth == -2)
                {
                    picWidth = this.GetIntFromQueryString("pw", -1);
                }
                return picWidth;
            }
            set 
            { 
                picWidth = value; 
            }
        }
        public int PictureHeight
        {
            get
            {
                if (picHeight == -2)
                {
                    picHeight = this.GetIntFromQueryString("ph", -1);
                }
                return picHeight;
            }
            set 
            { 
                picHeight = value; 
            }
        }
        public string FileUrl
        {
            get
            {
                if (string.IsNullOrEmpty(fileUrl))
                {
                    fileUrl = QueryString["fu"];
                }
                return fileUrl;
            }
            set
            {
                fileUrl = value;
            }
        }

        #endregion

        #region State

        private static readonly string dataKey = "CurrentHttpContextStore";

        public static WebContext Current
        {
            get
            {
                HttpContext httpContext = HttpContext.Current;
                WebContext context = null;
                if (httpContext != null)
                {
                    context = httpContext.Items[dataKey] as WebContext;
                }
                else
                {
                    context = System.Threading.Thread.GetData(GetSlot()) as WebContext;
                }

                if (context == null)
                {
                    if (httpContext == null)
                        throw new Exception("No WebContext exists in the Current Application. AutoCreate fails since HttpContext.Current is not accessible.");

                    context = new WebContext(httpContext, true);
                    SaveContextToStore(context);
                }
                return context;
            }
        }

        private static LocalDataStoreSlot GetSlot()
        {
            return System.Threading.Thread.GetNamedDataSlot(dataKey);
        }

        private static void SaveContextToStore(WebContext context)
        {
            if (context.IsWebRequest)
            {
                context.HttpContext.Items[dataKey] = context;
            }
            else
            {
                System.Threading.Thread.SetData(GetSlot(), context);
            }

        }

        public static void Unload()
        {
            System.Threading.Thread.FreeNamedDataSlot(dataKey);
        }

        #endregion

        public ForumUser User
        {
            get
            {
                return user;
            }
            set 
            { 
                user = value; 
            }
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -