I tried Application_AuthenticateRequest () in my Global.asax to better understand the flow of events. I am using the membership provider that comes with the MVC2 application by default.
I thought that if I did this:
public void Application_AuthenticateRequest(object sender, EventArgs args) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { authCookie.Expires = System.DateTime.Now.AddDays(-1);
The user can log in, but after loading the page after sending the login form they will be displayed as not logged in, since I destroyed their cookie.
However, it is not. Instead, they can successfully log in, and it will show that they are logged in when the page loads. On the next page they will be logged out.
I thought I didn’t destroy their cookie in time, so I put this code in Application_BeginRequest () inside my Global.asax. This gave the same results.
Does this mean that I still did not destroy their cookie on time, or do I misunderstand the flow of events?
source share