I am analyzing a problem from an old asp.net site made by one of my colleagues who left the company some months ago.
The problem is that we a few times have expierenced that two users sessions are mixed up, so that if for example two users are logged in, one user sees the other users data. As it happens very rarely (once in a month or so) it is difficult to figure out what goes wrong.
I have now stepped through his code for authentication and it goes like this:
- The user enter username/password on public page and press submit
- On
Page_Load
on Masterpage the code checks in a mySql database that the username/password is valid, not expired etc and return a unique userid if ok - The page then saves the loginpage in session like this (used for later logout):
HttpContext.Current.Session(Consts.CCookieName_LoginUrl) = Request.RawUrl
- Then the userid is saved like this:
FormsAuthentication.SetAuthCookie(userid, False)
- Then a redirect to the secure area is performed:
Context.Response.Redirect(secureurl, False)
- In
Page_Init
of masterpage of secure area the userid is read by:userid = Context.User.Identity.Name
- the user data is loaded acording to the userid
- The user navigates the secure area, ie. step 6 - 7 is repeated
- The user suddently sees another users data
I have some ideas on what is going wrong, but would like to have some input before modifying the code, so please anyone?