I’m a bit puzzled by the behavior of the default ASP.NET Authentication controls, by its lifecycle to be precise.
In my MasterPage, I added a LoginView Control which displays the nice [Login] or [Logout] links. When I am logged in and click on [logout], I set up the control to perform a redirection to the homepage of the application.
Internally, when a click on “logout” happens, a postback is triggered. The following steps happen (among others of course):
- The page that fired the postback is reinitialized
- The page that fired the postback is reloaded
- The LoggingOut event is fired
- The LoggedOut event is fired
- The page that fired the postback is PreRendered
- The redirection happens
- The target page is loaded (LoggedOut.aspx in my case)
On most of the pages, this works fine. But some pages expect some data to be initialized for their rendering to happens correctly. When this loggout postback occurs, the data isn’t correctly initialized, but the page is still PreRendered which leads to some… “unexpected behavior” >_<
My question is thus twofold:
- Why does this rendering step happens since the page won’t be displayed at all?
- Is there a way to prevent the rendering to happen?
Thanks a lot.
Tim
PS: here’s a small VS2010 sample project showing you the call sequence & page lifecycle if you want to try it out for yourself http://dl.dropbox.com/u/11764136/LoginTest.7z
Venemo’s answer gave me an idea that seems to be working.
Instead of relying on the
LoginStatuscomponent to perform the redirection, I registered the MasterPage hosting theLoginStatuscomponents to theLoginStatus.LoggedOutevent and fire the redirection “per hand” before the PreRender step can be called.I was concerned the
LoginStatuscomponent might remain dirty by doing this but sofar I haven’t found any issue with it e.g. “works until proven otherwise”.Remains the question of “why the component behaves like this” but I guess it was a design decision that will remain unanswered.
Edit: this works fine until you get the same problem for the “login” action. Haven’t found a way around this one yet.