用户信息验证基类

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. /// <summary>
  11. /// AdminPageBase 的摘要说明
  12. /// </summary>
  13. public class AdminPageBase : System.Web.UI.Page
  14. {
  15.     public AdminPageBase()
  16.     {
  17.         //
  18.         // TODO: 在此处添加构造函数逻辑
  19.         //
  20.     }
  21.     protected override void OnInit(EventArgs e)
  22.     {
  23.         base.OnInit(e);
  24.         this.Load += new EventHandler(Page_Load);
  25.     }
  26.     protected void Page_Load(object sender, EventArgs e)
  27.     {
  28.         string sUserID = Session["UserID"];
  29.         string sRole = Session["Role"];
  30.         if(sUserID == "")
  31.         {
  32.             WriteScript("window.alert('未登录不能操作后台管理功能!');window.top.location.href='/member/login.aspx';");
  33.             return;
  34.         }
  35.         if(sRole != "Administrator")
  36.         {
  37.             WriteScript("window.alert('你不是管理员,不能进入后台!');window.top.location.href='/member/login.aspx';");
  38.             return;
  39.         }
  40.     }
  41.     /// <summary>
  42.     /// 向客户端写入脚本块
  43.     /// </summary>
  44.     /// <param name="sScript">脚本块代码(不包含script标记)</param>
  45.     public void WriteScript(string sScript)
  46.     {
  47.         string sOut = String.Format("<script language='javascript'>{0}</script>", sScript);
  48.         this.RegisterClientScriptBlock("myscript", sOut);
  49.     }
  50.     /// <summary>
  51.     /// 向客户端页面弹出消息框
  52.     /// </summary>
  53.     /// <param name="sMsg">消息内容</param>
  54.     public void MsgBox(string sMsg)
  55.     {
  56.         string sScript = String.Format("window.alert('{0}');", sMsg.Replace("'""//'"));
  57.         WriteScript(sScript);
  58.     }
  59.     /// <summary>
  60.     /// 提示信息并自动跳转页面
  61.     /// </summary>
  62.     /// <param name="sMsg">提示的信息内容</param>
  63.     /// <param name="sPage">需要跳转的页面URL</param>
  64.     public void MsgAndTransfer(string sMsg, string sPage)
  65.     {
  66.         string sScript = String.Format("window.alert('{0}');window.location.href='{1}';", sMsg, sPage);
  67.         WriteScript(sScript);
  68.     }
  69. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值