470,586 Members | 1,335 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,586 developers. It's quick & easy.

ASP.NET 2.0 UserName of Currently Logged in User

Hi, can anyone advise me how I can access the UserName of a currently logged in user without using the LoginName control.

For instance I want to search tables I have created in my database that I have referenced by UserName as a foreign key. This is straightforward if I can identify what the currently logged in user's username is. But I can't??

I have tried Environment.UserName but this simply provides the username of my computer, rather than the currently logged in username of the application.

How can I access the Membership provider information such as UserName and UserID from the code of any website template?

Kind Regards,

Aug 1 '07 #1
2 9381
7,872 Expert 4TB
If you set in web.config that WindowsAuthentication is to be used for that aspx page, you can then retrieve the windows LoginID of that person.

I have a section where I require windows authentication then in my aspx page I used:
Expand|Select|Wrap|Line Numbers
  1. Logged in user: <%=User.Identity.Name %>
Note: You can use User.Identity.Name and the like in backend code as well.
Aug 1 '07 #2
That is magical and has ended hours of torment.

I'd eventually given up and tried as a work around creating a UserID profile variable at registration for anonymous users, and then converting it to a registered user variable which I could use in the templates as Profile.UserID.

I was still trying to figure out where to put the conversion event when I read this.


Thankfully I can scrap all that right now and use the clean method instead...

Thank you very much! GI
Aug 1 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by DMc2004 | last post: by
4 posts views Thread by 1qa2ws | last post: by
14 posts views Thread by Brent Burkart | last post: by
6 posts views Thread by John Dalberg | last post: by
1 post views Thread by Sudhakara.T.P. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.