How to get UserName of logon control from code

Discussion in 'ASP .Net' started by Froefel, Jul 11, 2007.

  1. Froefel

    Froefel Guest

    I have added a Login control to a Master Page. the control shows the
    currently logged in user (domainname\username).
    In one of the content pages, I need to access this name.
    I noticed that the Login control has a UserName property but it's in
    the Nonpublic properties, so it's not accessible from my code.

    I was trying to get to the name as follows:
    string username = ((LoginName)
    Master.FindControl("lnLoginName")).UserName;

    but that's failing...

    I was thinking of adding the username to a session variable, but I
    have a feeling that it's not the right approach in today's new world
    of web programming.

    Does anyone know how to get the current username in a code-behind file
    for a content page? Or is there something fundamental that I'm
    missing?

    Thanks in advance.

    -- Hans
     
    Froefel, Jul 11, 2007
    #1
    1. Advertising

  2. Froefel

    Tim Payne Guest

    Tim Payne, Jul 11, 2007
    #2
    1. Advertising

  3. Froefel

    Guest

    On Jul 11, 10:02 am, Froefel <> wrote:
    > I have added a Login control to a Master Page. the control shows the
    > currently logged in user (domainname\username).
    > In one of the content pages, I need to access this name.
    > I noticed that the Login control has a UserName property but it's in
    > the Nonpublic properties, so it's not accessible from my code.
    >
    > I was trying to get to the name as follows:
    > string username = ((LoginName)
    > Master.FindControl("lnLoginName")).UserName;
    >
    > but that's failing...
    >
    > I was thinking of adding the username to a session variable, but I
    > have a feeling that it's not the right approach in today's new world
    > of web programming.
    >
    > Does anyone know how to get the current username in a code-behind file
    > for a content page? Or is there something fundamental that I'm
    > missing?
    >
    > Thanks in advance.
    >
    > -- Hans


    You sure User.Identity.Name is not what you wanted? It is in the
    Form Authentication framework.
     
    , Jul 11, 2007
    #3
  4. Froefel

    Froefel Guest

    Thanks Anthony.

    User.Identity.Name does it.

    I'll have a look at the link Tim sent as well...
    Thanks to you both.

    -- Hans
     
    Froefel, Jul 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Dopierala Jr.

    Re: How to get Windows logon user credential?

    Ken Dopierala Jr., Aug 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,478
    cindy liu
    Aug 28, 2003
  2. armandotop
    Replies:
    2
    Views:
    391
    Peter Jansson
    Apr 13, 2005
  3. aemi
    Replies:
    1
    Views:
    16,059
  4. Kjell Kristiansson
    Replies:
    0
    Views:
    305
    Kjell Kristiansson
    Nov 30, 2005
  5. Shailesh Patel
    Replies:
    0
    Views:
    483
    Shailesh Patel
    Nov 8, 2006
Loading...

Share This Page