Jeff,
As I said in the comments on your question above, you should use the ClaimedIdentifier for the username, i.e. the first SetAuthCookie parameter. There is a huge reason for this. Feel free to start the topic on dotnetopenid@googlegroups.com if you want to learn more about the reasons.
Now about your question about the whole user object ... if you want to send this as a cookie, you will have to serialize your user object as a string, then you have to sign it somehow to protect it from user intervention. You can also encrypt it. Blah blah, this is a lot of work, and in the end you will have a big cookie going back and forth with every web request you donβt want.
What I do in my applications to solve the problem you are reporting is adding a static property to my Global.asax.cs file called CurrentUser. Like this:
public static User CurrentUser { get { User user = HttpContext.Current.Items["CurrentUser"] as User; if (user == null && HttpContext.Current.User.Identity.IsAuthenticated) { user = Database.LookupUserByClaimedIdentifier(HttpContext.Current.User.Identity.Name); HttpContext.Current.Items["CurrentUser"] = user; } return user; } }
Note that I cache the result in the HttpContext.Current.Items dictionary, which is specific to only one HTTP request, and keeps the user from choosing until one hit - and only retrieves it for the first time if the page really wants CurrentUser information.
Thus, the page can easily obtain the current registration of user data as follows:
User user = Global.CurrentUser; if (user != null) {
source share