网站简单权限管理

 
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
namespace XX.XX.BLL.UI
{
    public class ManagePage : System.Web.UI.Page
    {
        public ManagePage()
        {
            this.Load += new EventHandler(ManagePage_Load);
             
        }

        private void ManagePage_Load(object sender, EventArgs e)
        {
            //判断管理员是否登录
            if (!IsAdminLogin())
            {
                if (Core.Config.IsAgent)
                {
                    Response.Write("<script>parent.location.href='/admin/login.aspx'</script>");
                }
                else
                {
                    Response.Write("<script>parent.location.href='/login.aspx'</script>");
                } 
                Response.End();
            }
        }

        //public void Page_Error(Object source, EventArgs e)
        //{
        //    Exception objErr = Server.GetLastError().GetBaseException();
        //    JscriptMsg(objErr.Message.ToString(), "", "Error");
        //    Server.ClearError(); 
        //}
        #region 管理员============================================
        /// <summary>
        /// 判断管理员是否已经登录(解决Session超时问题)
        /// </summary>
        public bool IsAdminLogin()
        {
            if (Request.IsAuthenticated)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 取得管理员信息
        /// </summary>
        public Admin  GetAdminInfo()
        {
            if (IsAdminLogin())
            {
                string account = Context.User.Identity.Name;
                UserController UController = new UserController();
                return UController.GetAdmin(account);
            }
            return null;
        }
        public bool IsMoveOut
        {
            get {
                if (GetAdminInfo().ServerIp.IndexOf("xx.xxx.cn") != -1)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }
        public string _Account
        {
            get
            {
                return Context.User.Identity.Name;
            }
        }
        public string _AgentId
        {
            get
            {
                return GetAdminInfo().AgentId;
            }
        }
        #endregion

       

        #region JS提示============================================

        /// <summary>
        /// 添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        protected void JscriptMsg(string msgtitle, string url, string msgcss)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
        }

        /// <summary>
        /// 带回传函数的添加编辑删除提示
        /// </summary>
        /// <param name="msgtitle">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        /// <param name="callback">JS回调函数</param>
        protected void JscriptMsg(string msgtitle, string url, string msgcss, string callback)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\", " + callback + ")";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
        }
        #endregion

        
    }
}

然后其他的页面 都继承这个页面
namespace xx.xxx.Web.admin.Message
{
    public partial class EditMessage : xx.xx.BLL.UI.ManagePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                     }

你可能感兴趣的:(网站简单权限管理)