• 网站简单权限管理


     
    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)
            {
                         }
  • 相关阅读:
    HttpClient实现跨域请求
    Https如何让防止被监听
    Java 开发必会的工具类,代码量立减90%
    Java 临时变量的使用
    Java后端实现页面跳转
    Mybatis 实体类映射为null“坑”
    System.getProperty()_基本使用
    React项目中使用 FullCalendar v4 插件进行日程管理
    生成随机字符串工具示例
    java 图片与文件之间互转
  • 原文地址:https://www.cnblogs.com/naniannayue/p/2973964.html
Copyright © 2020-2023  润新知