By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,696 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,696 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Dave" <no****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #2

P: n/a
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/de...cnetlpmsdn.asp
(can also get this as a book, which I highly reccomend)
"Dave" <no****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 19 '05 #3

P: n/a
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
el********@hotmail.com


"Dave" wrote:
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

Nov 19 '05 #4

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

-Dave
"Elton W" <El****@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
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
el********@hotmail.com


"Dave" wrote:
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

Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.