I am developing an ASP.Net MVC 3 web application with Entity Framework 4. When a user enters my application, I would like to save his user object (firstName, lastName, etc.) in a session, which can then be accessed throughout expression.
I understand that this may not be a good idea, because when the ObjectContext is closed / deleted, the user object is separated, and the user details may be lost.
I thought that another method could be, when the user logs in, assign the user ID (primary key) to the session variable, i.e.:
HttpContext.Current.Session["currentUserID"] = user.userID;
Then create a class in the UserService class as follows:
public static User CurrentUser
{
get
{
return Data.DBEntities.Users.Where(u => u.userID == HttpContext.Current.Session["currentUserID"]).FirstOrDefault();
}
}
, currentUserID. , ,
Cannot convert lambda expression to type 'string' because it is not a delegate type
Delegate 'System.Func<Asset.Model.User,int,bool>' does not take 1 arguments
, ?
.