Search code examples
asp.netsessionuserid

Holding userid in ASP.net


I am using ASP.net for developing an intranet website. I need to hold the userid across all postbacks for all the pages in the website. Is it advisable to hold those information in Session or somether way is available.


Solution

  • If using Forms Authentication, then the username will be available as:

    Page.User.Identity.Username
    

    If you need to hold another piece of information alongisde this, then use Session.

    PS. I recommend using a class to wrap your session variables for strong-typedness and potential default values.