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

ASP.NET/VB Get Windows Login (not ASPNET user)

P: n/a
I have been trying to figure out how to get the user login name of the
user using an asp.net page. This is for an intranet. I got as far as
doing something like this:

Dim wpMain as WindowsPrincipal
wpMain = new WindowsPrincipal(WindowsIdentity.GetCurrent())
Label1.Text = wpMain.Identity.Name

However, that will display <COMPUTERNAME>\ASPNET. I don't need the
ASPNET user, I need the user who is logged into the computer.
Any ideas?

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Kevin,

Make sure you have Anonymous access switched off in IIS Manager and
Integrated switched on.

Ken

"SirPoonga" <ke*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have been trying to figure out how to get the user login name of the
user using an asp.net page. This is for an intranet. I got as far as
doing something like this:

Dim wpMain as WindowsPrincipal
wpMain = new WindowsPrincipal(WindowsIdentity.GetCurrent())
Label1.Text = wpMain.Identity.Name

However, that will display <COMPUTERNAME>\ASPNET. I don't need the
ASPNET user, I need the user who is logged into the computer.
Any ideas?


Nov 19 '05 #2

P: n/a
I've been working on similar things I found that I needed to disable
anonymous access and turn on integrated windows authentication. This however
will mean that users will need to sign in.

You also want to change the authenication mode in your web config file.

<authentication mode="Windows" />

If you find out a way to get the ID without the user having to login then
please post it here.


"SirPoonga" wrote:
I have been trying to figure out how to get the user login name of the
user using an asp.net page. This is for an intranet. I got as far as
doing something like this:

Dim wpMain as WindowsPrincipal
wpMain = new WindowsPrincipal(WindowsIdentity.GetCurrent())
Label1.Text = wpMain.Identity.Name

However, that will display <COMPUTERNAME>\ASPNET. I don't need the
ASPNET user, I need the user who is logged into the computer.
Any ideas?

Nov 19 '05 #3

P: n/a
"Unrecognized configuration section 'authentication'"
Hmmmm. I looked at msdn.micosoft.com on how to do the authentication
mode.

I will have to talk to the IT people. I don't have control over the
IIS server. I might not be able to do what I want.

Nov 19 '05 #4

P: n/a
Hi SirPoonga,

Try out the following code:

Imports System.Security
.........
.........

Dim authUserName As String
Dim aspUserName As String
authUserName = User.Identity.Name
aspUserName = Principal.WindowsIdentity.GetCurrent.Name
Label1.Text = "You are: " & authUserName
Label2.Text = "This page runs as: " & aspUserName
and ,

1) Start IIS
2) Expand your server and its default Web site, right-click the "your
project" site, and then click Properties.
3) On the Directory Security tab in the WindowsSite Properties dialog box,
click the Edit button in the "Anonymous access and authentication control"
section.
4) Click to clear the Anonymous access check box, verify that the Integrated
Windows authentication check box is selected, and then click OK.
5) Click OK to close the "your project" Properties dialog box.
6) Switch back to Visual Studio, and then run the project. Confirm that the
page is displayed with the following message:
You are: "Your Windows user name"
This page runs as: DomainOrServer\ASPNET
For more clarification feel free to touch with me...

Enjoy Programming....

Kombaraj .A

"SirPoonga" wrote:
I have been trying to figure out how to get the user login name of the
user using an asp.net page. This is for an intranet. I got as far as
doing something like this:

Dim wpMain as WindowsPrincipal
wpMain = new WindowsPrincipal(WindowsIdentity.GetCurrent())
Label1.Text = wpMain.Identity.Name

However, that will display <COMPUTERNAME>\ASPNET. I don't need the
ASPNET user, I need the user who is logged into the computer.
Any ideas?

Nov 19 '05 #5

P: n/a
That's awesome. Can I just get the user name, no domain? Or am I just
going to have to parse that. Nothing a simple split() can't solve.

Nov 19 '05 #6

P: n/a
Ok, I just tried this and it works on my machine running IIS for
development.
However, when I had an coworker try and open the page authentication
was required.
I guess I don't understand what is going on. How does someone else
view the page then? Do they have to login to something? Do I have to
setup User permissions somewhere?

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.