Any way to determine, via code, the user's Windows Login Name and domain?

D

Dave

Greetings,

I have a web application that will be hosted on our intranet. I would like
to determine, via code the user's windows login name and domain in the
following format: DOMAIN\loginname

Is this possible? Thanks,

-Dave
 
R

Rafal Gwizdala

Yes, this is possible.
Use Windows authentication in your web app, then examine the User object
from your web page code. It should be WindowsPrincipal with WindowsIdentity,
and with identity.Name set to windows account name.
I might be wrong in some technical details as this is what I remember, but
in general it works.

Best regards
Rafal Gwizdala
 
B

Brad

Simplistically put, you need the following:
1) In IIS console you need to set the Authentication method for the
application folder to Integrated Windows Security (typically this is just
unchecking anonymous access)
2) Make sure the NT folder's security permissions allow access for the
required users i.e. Authenticated Users...or at least the users / groups
notes in next step
3) In web.config enable impersonation <identity impersonate="true">
And allow all users...or at least the domain users and/or groups who
should have access
i.e. <authorization>
<allow users="*">
</authorization>
4) Use System.Security.Principal (vb Imports or c# Using)
5) Get the name in code i.e.in vb
' get the domain\user name
Dim userName As String = WindowsIdentity.GetCurrent.Name

I would strongly reccomend you look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetlpmsdn.asp
(can also get this as a book, which I highly reccomend)
 
G

Guest

Hi Dave,

Use following steps:

1) In Web.Config file, set Windows authentication and deny anonymous:

<authentication mode="Windows"/>
<authorization>
<deny users="?" /> <!-- deny anonymous -->
<allow users="*" /> <!-- Allow all users -->
</authorization>

2) In code use:
Page.User.Identity.Name
It gives DOMAIN\loginname.

HTH

Elton Wang
(e-mail address removed)
 
D

Dave

Thank you everybody for the responses, I appreciate it. I will give them a
try this morning.

-Dave
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top