Q:

Asp.net, where to store the username of logged in user?

When a user log into my asp.net site I use the following code:
FormsAuthentication.RedirectFromLoginPage(userid, false);

As I often need to use the userid I can then later get the userid by:
string userid = System.Web.HttpContext.Current.User.Identity.Name;

Now I also want to show the logged in username on each page and my questions is therefore where do I place the username best if I need to use it on every page. User.Identity.Name is already taken by the userid so I can't use that one. Another solution would be to get the username from the database on each page, but that seems like a bad solution. 
So: Is the best way to use Sessions to store the username? 

A:

There are essentially 6 different ways to store information, each with it's own benefits and drawbacks.

Class member variables.  These are only good for the life of one page refresh.
HttpContext variables.  Like class member variables, only good for one page refresh. 
ViewState, these are passed from page to page to keep state, but increase the size of the downloaded data.  Also, not good for sensitive information as it can be decoded. 
Cookies.  Sent on each page request.  Also not good for sensitive information, even encrypted. 
Session.  Not passed to the end user, so good for sensitive information, but it increases the resource usage of the page, so minimizing usage for busy sites is important.
Authentication Cookie User Data - This is like like cookies, but can be decoded with the authentication data and used to create a custom IIdentity provider that implements your desired Identity information, such as Name or other profile information.  The size is limited, however.

A:

You can store just about anything in SessionState in asp.net.  Just be careful and store the right things in the right places (you can also use ViewState to store variables.
Check this out for how to use SessionState to store and retrieve variables across postbacks.

