yuanweisen

 

后台的父类

/// <summary>
        /// 当前员工
        /// </summary>
        public Employee CurrentMaster
        {
            get {
                if (Session["CurrentMaster"] == null)
                    return null;
                return (Employee)Session["CurrentMaster"];
            }
            set { Session["CurrentMaster"] = value; }
        }

        /// <summary>
        /// 当前路径
        /// </summary>
        public string CurrentPagePath
        {
            get
            {
                return this.Request.Path.Substring("/Admin/".Length).ToLower();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (CurrentMaster == null)
            {
                ShowError(ErrorCode.Login);
            }
            else if (CurrentPagePath != "main.aspx" && !CurrentMaster.Role.MenuTable.ContainsValue(CurrentPagePath))
            {
                ShowError(ErrorCode.Right);
            }
        }

        protected void ShowError(ErrorCode ec)
        {
            Response.Redirect("/Admin/Error.aspx?err=" + (int)ec);
        }

 

辅助的错误类:

public enum ErrorCode
    {
        //未知错误
        NoneErr,
        //未登陆
        Login,
        //没有权限
        Right
    }

跳转到错误布面代码

 private ErrorCode ErrMsg
        {
            get { return (ErrorCode)RequestHelp.QID("err"); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (ErrMsg)
            {
                case ErrorCode.Login:
                    lblErrMsg.Text = "未登陆";
                    break;
                case ErrorCode.Right:
                    lblErrMsg.Text = "没有权限";
                    break;
                case ErrorCode.NoneErr:
                    lblErrMsg.Text = "未知错误";
                    break;
            }
        }

posted on 2008-12-09 18:28    阅读(176)  评论(0编辑  收藏  举报

导航