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

S

SirPoonga

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?
 
K

Ken Cox [Microsoft MVP]

Hi Kevin,

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

Ken
 
G

Guest

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.
 
S

SirPoonga

"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.
 
G

Guest

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
 
S

SirPoonga

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.
 
S

SirPoonga

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?
 
Joined
Sep 14, 2009
Messages
1
Reaction score
0
Has this been resolved. I have a similar problem. I'm looking for system's (Windows) login id and not the ASPNET user id. I'm running application under 'Anonymous access' and 'Windows Integrated authentication' in order to avoid login dialog being displayed for other users.

If I have to remove 'anonymous access', how would I prevent the authentication dialog for other users.

Thanks,
 

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
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top