Can asp.net find Windows login name?

B

Brad Burke

Can I create an asp.net web page that finds the current user by looking at
their Windows login name or are security setting going to limit me?

When a page first opens, can I use code similar to my current VB6 code:

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function GetOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If (lngX > 0) Then
GetOSUserName = Left$(strUserName, lngLen - 1)
Else
GetOSUserName = vbNullString
End If
End Function

Thanks!
 
P

Patrick.O.Ige

That would solve your problem as Karsten adviced
Or even use ServerVariable LOGON_USER
But you need to have have Integrated Windows Auth checked in IIS to get the
user logged on
Patrick
 
D

Dominick Baier [DevelopMentor]

Hello Patrick.O.Ige,

don't rely on server variables

use Context.User.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top