Hi,
I’m trying to figure out whether FormsAuthentication.RedirectFromLoginPage (called inside method M()), performs redirection the moment method M finishes its execution, or whether page first completes its lifecycle and only then redirects. But I can't figure it out due to inconsistent behavior:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
FormsAuthentication.RedirectFromLoginPage("someUser", false);
}
protected void LogOut_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Session["LogOut"] = "LogOut_Click event handler";
}
protected void ClickMe_Click(object sender, EventArgs e)
{
Session["ClickMe"] = "ClickMe_click event handler";
}
If on postback user clicks LogOut button, then *LogOut_Click()* is executed prior to page being redirected. But if on postback user clicks on ClickMe button, the page is redirected before *ClickMe_Click* event handler is called.
Why is that? Thus, based on what criteria does FormsAuthentication.RedirectFromLoginPage decide which event handlers should be executed before the redirection?
thanx
EDIT:
The FormsAuthentication.RedirectFromLoginPage() method has nothing to do with logging out. It's used to manually log someone in and redirect them to the page they were originally trying to access.
I didn’t imply that it has anything to do with logging out
However, looking at your code samples, you could be asking why the code continues to execute in the LogOut_Click function even if the user is logged out.
No, I didn’t ask that either.
Now, it also occurs to me that you could be asking about FormsAuthentication.RedirectToLoginPage instead of RedirectFromLoginPage.
I didn’t ask that either
What I’m asking is why when FormsAuthentication.RedirectFromLoginPage is called inside Page_Load, if postback was caused by LogOut button, then LogOut_Click() method does run before page is redirected, but if ClickMe button causes the postback, ClickMe_Click() event handler doesn’t have a chance to run before a page is redirected. In other words, I would expect that ClickMe_Click would also have a chance to run before page was redirected ( assuming ClickMe button caused a postback )