How to get UserName of logon control from code

F

Froefel

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
 
A

antonyliu2002

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.
 
F

Froefel

Thanks Anthony.

User.Identity.Name does it.

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

-- Hans
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top