I have a log in page and a content page (i.e. Home page).
If the user has not logged in, s/he will be redirected to the login page. At the login page, after the user has successfully logged in, the credential will be stored in a Session variable.
My question is, what would be the difference if I check the login status during the PreInit
and Page_Load
? i.e.
What is the difference between this:
protected void Page_PreInit(object sender, EventArgs e)
{
//If the user is not logged in, redirect the user to login page
if (Session["isLogin"] == null || Session["isLogin"] == 0)
{
Response.Redirect("~/Login");
}
}
and this:
protected void Page_Load(object sender, EventArgs e)
{
//If the user is not logged in, redirect the user to login page
if (Session["isLogin"] == null || Session["isLogin"] == 0)
{
Response.Redirect("~/Login");
}
}
Which of these is the more recommended way of implementing it? Pros and Cons?