参考:public class BasePage : System.Web.UI.Page
{
     //验证是否成功登录
        public bool LoginOk
        {
            get
            {
                return (Session["LoginOk"] != null && (bool)Session["LoginOk"]);
            }
            set
            {
                Session["LoginOk"] = value;
            }
        }  //当前用户帐号
        public string CurrentAccount
        {
            get
            {
                return (Session["Account"] != null ? Session["Account"].ToString() : string.Empty);
            }
            set
            {
                Session["Account"] = value;
            }
        }        //登录验证
        public void LoginAuthorizationed()
        {
            if (!LoginOk)
            {
                Response.Redirect("~/default.aspx");
            }
        }
}ublic partial class Member: BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginAuthorizationed();  
       //other code  
     }
}

解决方案 »

  1.   

    不要使用继承,而是将代码写到另一个页面或用户控件中,使用@Register指令包含进去
      

  2.   

    谢谢,有效。但我还是不太理解。在构造函数中不能使用Session吗?
      

  3.   

    不要使用继承,而是将代码写到另一个页面或用户控件中,使用@Register指令包含进去然后怎么办?谢谢回复
      

  4.   

    我感觉,可以使用控件写好验证的类,例如:1楼的代码,然后,在你要验证的页面里的相应控件里加在
    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //正常登陆!
            }
        }
    就可以了.