views:

377

answers:

1

I've got an implementation similar to this: http://stackoverflow.com/questions/1710875/better-way-of-doing-strongly-typed-asp-net-mvc-sessions

for quick access to frequently-needed user data... but i have two questions:

1) will there ever be a time when a user is logged in, but the session would be invalid or reset? I always thought that as long as a user is signed in, their session is valid...

2) I want to populate the data when the user logs in, but I don't know how to access that data at login. there is a LogOn method in the AccountController, but although there is a FormsService.SignIn method, I don't see where it's actually signing in the user, because the Membership.GetUser() returns null until AFTER the page redirects...

I'm guessing that I'm doing this wrong, and that I shouldn't try to make a generic method to retrieve the session, but rather map individual methods to the session values, and repopulate them from the user data manually if they are null..

what do you think?

+1  A: 
  1. There's a difference between session and authentication. Session is available throughout the whole application, even if a user is not signed in.
  2. In the default ASP.NET MVC 2.0 project template you can populate the session data just after the call of FormsService.SignIn. This is where the user credentials have been validated and an authentication cookie will is written to the response. You can use the provided username to fetch any user information from the database if you need to.
Darin Dimitrov
thank you, this makes perfect sense
Josh