读书人

重写事件OnInit 导致quot;此网页包含重定向

发布时间: 2012-04-20 15:27:03 作者: rapoo

重写事件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);
}
}
}
}

读书人网 >asp.net

热点推荐