Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My.User.Name is blank 1

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
Code:
MessageBox.Show(My.User.Name)
The above code returns nothing. Anybody know why?
 
This uses windows authentication and returns something like: <server>\<userName>
Try MessageBox.Show(My.User.IsAuthenticated). What is it, true or false ?
 
Sure, this means that you are not authenticated and that is the reason that you do not have a username.
 
Thanks again. After your last post I decided that maybe I misunderstood the My.User object so I dug into the MSDN documentation. I found this blurb:

For Windows applications, only projects built on the Windows Application template initialize the My.User object by default. In all other Windows project types, you must initialize the My.User object by calling the My.User.InitializeWithWindowsUser Method explicitly or by assigning a value to CurrentPrincipal.

I assumed my application was built on a Windows Application template because that is the template I chose in the New Project dialog box.

So I put My.User.InitializeWithWindowsUser in my Form_load and My.User.Name returned my username that I used to logon to my laptop with. Sounds to me like it should have worked by default.
 
Thanks! Wish I could give you two stars. ;) I'm going to check out the link.
 
heh tnx again!

My opinion is that you should take your time and have a look on most of the samples. They are very nice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top