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!

How do I find domain of users logon?

Status
Not open for further replies.

eyorre

Programmer
Jan 24, 2002
32
GB
I have been looking at replies to this sort of question but they go into a lot of detail and I am hoping that they contain a lot of stuff that I don't need as they are a bit over my head.

Basically I want my ASP page to retrieve the domain name of the Windows logon. Then if the domain is X then I can run some ASP so that the user can only see the appropriate records in a SQL Server table.

I was thinking along the lines of:

strNetworkID = Request.ServerVariables("LOGON_USER")

Is this correct way to get windows logon info? Then I need to be able to pull out the name of the domain from strNetworkID. At moment I get nothing so not sure what form this string will take. Is this were I need to turn off the anonymous access?

I will then use the domain name to limit the records the user sees
set rs=objonnection.execute("SELECT * FROM myTable WHERE myDomain=X")

Can anyone advise? Maybe I am over simplyfying!
 
Is this were I need to turn off the anonymous access?

Yes, the browser will not send credentials until the server gives it a 401 Authorization Required. Subsequent requests will send credentials which you can read from LOGON_USER.
 
Thanks very much Sheco. This was very helpful. I now have the anonymous access turned off and I can get hold of the domain name fine.
 
This bit of code is quite helpful if you have a table of users with their windows usernames and a UserID field (autonumber) and you want to retrieve the userid so you can log it somewhere else.

<%
Set DB = Server.CreateObject("ADODB.Connection")
Set TBL = Server.CreateObject("ADODB.RecordSet")

DB.Mode = adModeReadWrite
DB.Open "db"

Set Login = Request.ServerVariables("LOGON_USER")
TBL.Open "SELECT UserID FROM Users WHERE UserName='" & (Right(Login, (Len(Login)-Instr(Login, "\")))) & "'", DB
If Not TBL.EOF Then
UserID=TBL("UserID")
Else
UserID=0
End If
TBL.Close

Set TBL=Nothing
Set DB=Nothing
%>
 
>Set Login = Request.ServerVariables("LOGON_USER")
This can't be right?
 
S/he probably means
Code:
 [s]Set[/s] Login = Request.ServerVariables("LOGON_USER")

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top