locked
Assigning Session Variable The UserName RRS feed

  • Question

  • User1944873914 posted

    Hi,

     Im using the built-in login controls within Visual Studio 2005 and Im wondering is there a way to assign the current users username to a session variable so that I can use it for other purposes on the website. If this is possible can you point me in the right direction please.

     Many thanks,

     Paz146

    Tuesday, April 15, 2008 9:35 AM

Answers

  • User-1995538749 posted

    There's really no need to do that when you can access the currently logged-in user's name one of two ways.

    Within your page:

    string userName = this.User.Identity.Name;

    Within a class:

    string userName = HttpContext.Current.User.Identity.Name;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2008 9:43 AM

All replies

  • User-1995538749 posted

    There's really no need to do that when you can access the currently logged-in user's name one of two ways.

    Within your page:

    string userName = this.User.Identity.Name;

    Within a class:

    string userName = HttpContext.Current.User.Identity.Name;

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2008 9:43 AM
  • User1944873914 posted

    Yeah I thought they'd be an easy way of doing it, thanks for the quick reply it worked perfect!

     Thanks

     

    Paz146

    Tuesday, April 15, 2008 9:56 AM