日期:2014-05-18  浏览次数:20451 次

重写事件OnInit 导致"此网页包含重定向循环"
C# code
        protected override void OnInit(EventArgs e)
        {
         
                if (Session["用户名"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
          
            base.OnInit(e);
        }


代码如上 新人求解释

------解决方案--------------------
C# code

//重写这个试试
protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }

------解决方案--------------------
OnInit(EventArgs e)
{
base.OnInit(e);
if (Session.Keys.Count <= 0)
{
Response.Redirect("~/TMSLogin.aspx", true);
}
else
{
if (Session["Role_id"] != null)
{
string role = Session["Role_id"].ToString();
if (role != "1") //1代表管理员
{
Response.Redirect("~/TMSLogin.aspx", true);
}
}
}
}