How can I check a variable and redirect to another page before the page loads using ASP.NET?
I\'m aware of the life cycle, and PageInit() sounds like it
I'm not aware of an onpageinit attribute. The session variable is independent of the page life cycle. Session is always available. Assuming you always use the same master page, insert your code in Pre_Init in the code behind of the Master Page.
To do this, add the override to the code behind:
protected override void OnPreInit(EventArgs e)
{
if (session.logged_in == false)
{
Response.Redirect("login.aspx", false);
}
}