【原】web页面登陆验证

  

using Itcast.Mall.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

namespace Itcast.Mall.WebApp.Code
{
    //AuthBasePage是自己新建的一个类,然后让这个类继承System.Web.UI.Page; 
    public class AuthBasePage:Page
    {
        protected User CurrentUser;
        //重载OnLoad方法,这里用来对session的内容进行判断
        protected override void OnLoad(EventArgs e)
        {
            //如果session为空,就说明没有登陆,或者登陆失败,让页面跳转到登陆页面,并且把当前网址传过去;
            
            if(Session["current_user"]==null)
            {
                //session中没有用户信息,就跳转到登陆页面,并且把当前页面的URL传过去
                //redirect是自己在登陆页面表单里定义的一个隐藏控件,用来接收上次访问的页面URL;
                Response.Redirect("/Account/login.aspx?redirect=" + HttpUtility.UrlEncode(Request.Url.ToString()));
            }
            //session对象存在,就将这个对象转成指定的实体
            CurrentUser = Session["current_user"] as User;
            base.OnLoad(e);
        }
    }
}

 

posted @ 2015-04-27 23:59  哥本哈根  阅读(777)  评论(0编辑  收藏  举报