Folks, I ran into an unexpected trap in the ASP.NET page lifecycle last
night. I wonder if others have hit this problem and have a better
workaround.

 

To protect against crashes due to session timeouts or IIS restarts I usually
have something like this in the PreInit event of a common base page for all
of my aspx pages:

 

protected override void OnPreInit(EventArgs e)

{

    // Sanity check that app and session data are present as expected.

    // The call will Redirect to a generic warning page if it fails.

    if (!IsPageEnvironmentOK())

    {

        return;

    }

    base.OnPreInit(e);

}

 

I still had crashes happening despite this sanity checking. It turns out
that the ItemCommand handler of my grids and repeaters run before the
PreInit. I had to put my environment check call at the start of all the
ItemCommand handler methods, and now I seem to have plugged all the crash
points.

 

I was just surprised and tricked by the sequence of processing.

 

Greg

Reply via email to