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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting NT Userid in ASP and refreshing page based on NT UserID 1

Status
Not open for further replies.

HLotis

Programmer
Dec 14, 1998
31
0
0
US
Getting NT Userid in ASP and refreshing page based on NT UserID
 
Here is some code I found to get the nt user name using VB.&nbsp;&nbsp;However, I have not been able to successfully transfer the functions to ASP. <br><br><br>Private Const UNKNOWN = _<br>&quot;(Value Unknown Because System Call Failed)&quot;<br><br>Private Declare Function GetUserName Lib &quot;advapi32.dll&quot; _<br>Alias &quot;GetUserNameA&quot; (ByVal lpBuffer As String, nSize _<br>As Long) As Long<br><br>Public Function GetCurrentUserName() As String<br><br>Dim l As Long<br>Dim sUser As String<br><br>sUser = Space$(255)<br>l = GetUserName(sUser, 255)<br><br>'strip null terminator<br><br>If l &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;GetCurrentUserName = Left(sUser, InStr(sUser, Chr(0)) - 1)<br><br><br>Else<br>&nbsp;&nbsp;&nbsp;Err.Raise Err.LastDllError, , _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;A system call returned an error code of &quot; _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& Err.LastDllError<br>End If<br><br>End Function
 
Here, I just wrote this routine which will return the NT username.&nbsp;&nbsp;Of course to get NT user name, you must have authentication set up on the webserver... don't try to do it with anonymous access allowed (duh).<br><br>Function NTUserName()<br>&nbsp;&nbsp;&nbsp;&nbsp;'declare variables<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim logon, myArray<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'will return Domain\Username or just Username depending<br>&nbsp;&nbsp;&nbsp;&nbsp;'if the user is logged into the domain or their local machine.&nbsp;&nbsp;also browser dependent.&nbsp;&nbsp;go figure.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logon = Request.ServerVariables(&quot;LOGON_USER&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'so we split the logon variable by the &quot;\&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myArray = Split(logon, &quot;\&quot;, -1, 1)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'take the upper bound of the logon variable<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;logon = myArray(Ubound(myarray))<br><br>&nbsp;&nbsp;&nbsp;&nbsp;'and you're left with just the NT Username<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NTUserName = logon<br><br>End Function<br><br>Happy programming
 
Jfriestman,<br>Will this work with PWS.If so do you know how to set authentication in PWS?
 
JF,<br>Thanks for your clafification. I should look more onto what is available under server variables. My Access friends were telling me about Windows api calls to get the NT Userid. You should put this under FAQ for ASP and VI.<br>HL
 
Yes it will work with PWS.&nbsp;&nbsp;Set the authentication for NT Challenge Response (IE) and Basic Authentication (for Netscape).&nbsp;&nbsp;How do you set authentication...<br>From the Management console, choose directory security... the tabs and dialogs are pretty intuitive from there. <p> <br><a href=mailto: > </a><br><a href= View my Brainbench transcript</a><br>Brainbench MVP
 
hi there,
I am newbie.Finaly I found how to return nt user code.I am using DMX where do i have to paste your code and how to display on the page to test and then make not visible
thank you
Nat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top