PostBack beefore Session Check
Question
Shouldn't PostBack be checked before Session
protected void Page_Load(object sender, EventArgs e)
{
if (Session["login"] != null && Session["login"].ToString() == "1")
{
if (!IsPostBack)
{
LoadData();
}
}
else
{
Response.Redirect("login.aspx");
}
}
Solution
This depends on what you are doing, and typically I would say no.
It is possible for session to expire between the time that the page loaded, and the time that a postback happened. Granted they would have to sit on the page for quite a while, but it could happen.
Checking session first, ensures that the session information is always available.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow