会话类 Power.cs

来源:互联网 发布:弗洛伊德算法函数 编辑:程序博客网 时间:2024/05/20 06:07

using System;
using System.Web;

namespace Silk_Road.Class
{
 /// <summary>
 /// Power 的摘要说明。
 /// </summary>
 public class Power
 {
        /// <summary>
        /// 判断会话是否存在,并确认此页面或方法是否可被访问
        /// </summary>
        /// <param name="Power_Name">
        ///    权限内容,为 页面所在目录 + ":" + 执行命令 的组合
        ///    {                                  
        ///        注:执行命令                                                                        
        ///            增加数据--"Add"
        ///            管理数据--"Manage"  (包括修改、删除)
        ///            类别管理--"Sort"
        ///            数据审核--"Pass"
        ///            权限管理--"Power"
        ///     }
        /// </param>
        /// <returns>bool</returns>
        public static void Access(string Power_Name)
        {
            bool Accessed = false;
            Power.Session_State (); //判断会话是否存在

            string[] PowerList = (string[])HttpContext.Current .Session ["Admin_Power"];  //取权限数组
            //判断此管理员是否有此权限
            foreach(string str in PowerList)
            {
               if(Power_Name == str)
                   Accessed = true;
            }
            if(Accessed == false)
            {
                HttpContext.Current.Response .Redirect ("/Manage/error.aspx");
                HttpContext.Current .Response .End ();
            }
        }

        /// <summary>
        /// 判断会话是否存在,不存在就重新登录
        /// </summary>
        public static void Session_State()
        {
            //判断会话是否存在,不存在,报错,并重定向到Login.aspx
            if(HttpContext.Current .Session ["Admin_Name"] == null)
            {
                HttpContext.Current.Response .Write ("<script LANGUAGE='javascript'>alert('您的会话过期,请重新登录!');window.location='/Manage/Login.aspx';</script>");
                HttpContext.Current .Response .End ();
                return;
            }
        }
 }
}

posted

原创粉丝点击