global.cs

来自「最好用的站点内容管理系统 全部源代码都有」· CS 代码 · 共 70 行

CS
70
字号
//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Web;
using System.Text;
using NetCMS.Model;

namespace NetCMS.Global
{
    public class Current
    {
        public static string SiteID
        {
            get
            {
                return GetInfo().SiteID.Trim();
            }
        }
        public static string UserNum
        {
            get
            {
                return GetInfo().UserNum;
            }
        }
        public static string UserName
        {
            get
            {
                return GetInfo().UserName;
            }
        }
        public static string ClientIP
        {
            get
            {
                return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
        }
        public static bool IsTimeout()
        {
            try
            {
                GlobalUserInfo info = GetInfo();
                return false;
            }
            catch
            {
                return true;
            }
        }
        public static void Set(GlobalUserInfo info)
        {
            HttpContext.Current.Session["SITEINFO"] = info;
        }
        private static GlobalUserInfo GetInfo()
        {
            if (HttpContext.Current.Session["SITEINFO"] == null)
                throw new Exception("您没有登录系统或会话已过期,请重新登录");
                //return (GlobalUserInfo)HttpContext.Current.Session["SITEINFO"];
            else
                return (GlobalUserInfo)HttpContext.Current.Session["SITEINFO"];

        }
    }
}

⌨️ 快捷键说明

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