views:

117

answers:

1

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");
    }
}
+1  A: 

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.

Mitchel Sellers