统一身份验证

定义一个基类:

public class BasePage:System.Web.UI.Page
{
    public BasePage()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
        this.Load += new EventHandler(BasePage_Load);
    }

    void BasePage_Load(object sender, EventArgs e)
    {
        //throw new Exception("The method or operation is not implemented.");
        //如果用户没有登录,就跳转到登录页面
        if (Session["UserName"] == null)
        {
            Response.Redirect("~/admin/login.aspx");
        }
    }
}

然后在所有需要身份验证的页面继承BasePage类即可

posted @ 2009-06-12 12:42  aochen  阅读(170)  评论(0)    收藏  举报