Yes we're handling authentication ourselves. We have a DB that has the users and need to use that.
For this use case, is there a better way to do this?
You could consider using a Cookie ala
Forms Authentication to handle this. Basically after your user has logged in, you could create a Cookie associated to that particular user which would be stored in the browser for a certain period of time (designated by the Expires property on the Cookie).
This would be a much better approach than using the Session and it would be much more resilient.
You could either create the cookies manually :
// Create your cookie
HttpCookie myCookie = new HttpCookie("AuthenticationCookie",YourUserName);
// Indicate the cookie will persist for 12 hours
myCookie.Expires = DateTime.Now.AddHours(12);
// Add the cookie to the Response
Response.Cookies.Add(myCookie);
All-Star
114593 Points
18503 Posts
MVP
Re: Session variables sometimes disappearing
Apr 02, 2015 09:39 AM|Rion Williams|LINK
You could consider using a Cookie ala Forms Authentication to handle this. Basically after your user has logged in, you could create a Cookie associated to that particular user which would be stored in the browser for a certain period of time (designated by the Expires property on the Cookie). This would be a much better approach than using the Session and it would be much more resilient.
You could either create the cookies manually :
or by actually using the built-in FormsAuthentication.SetAuthCookie() method :