?
Solved

Getting the Windows Login name in ASP.NET

Posted on 2007-10-02
5
Medium Priority
?
1,440 Views
Last Modified: 2013-11-07
I am running this chunk of code on my ASP.NET page:

Dim networkuser As WindowsIdentity
Dim networklogon As String
Dim arrnetworklogon As Array
Dim loginname As String
       
 'get network user data
networkuser = WindowsIdentity.GetCurrent
networklogon = networkuser.Name 'this will return the domain\network login
       
arrnetworklogon = Split(networklogon, "\")
loginname = arrnetworklogon(UBound(arrnetworklogon)) 'extract the last part of the network logon

When testing the application under my local machine, it is working fine. loginname shows my windows login.

When I moved it to the production server, loginname becomes "NETWORK SERVICE".  Do I need to set up anything on IIS in order to make it work?

The application I'm building is an intranet application.  


         
0
Comment
Question by:crickpaolo
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
skiltz earned 1500 total points
ID: 20002016
Have you tried user.indentity.name?
0
 

Author Comment

by:crickpaolo
ID: 20002110
Thanks skiltz.   I googled "user.indentity.name" and I couldn't find a clean example of how to use it.  Do you have any code snippets that will get the windows login using user.indentity.name?  I am not sure what namespaces to include, how to declare it etc.

 
0
 

Author Comment

by:crickpaolo
ID: 20002224
Ok, I found out how to use user.identity.name by modifying my code like this:

Dim networklogon As String
Dim arrnetworklogon As Array
Dim loginname As String
       
'get network user data
networklogon = User.Identity.Name
arrnetworklogon = Split(networklogon, "\")
loginname = arrnetworklogon(UBound(arrnetworklogon)) 'extract the last part of the network logon

When I run it, I am getting a blank  for logginname.  What am I doing wrong?

Thanks.
   
0
 
LVL 7

Expert Comment

by:skiltz
ID: 20003099
Do you get a value for networklogon or User.Identity.Name??

if so

  Dim loginName As String
        Dim lgDash As Long
        lgDash = User.Identity.Name.IndexOf("\")
        loginName = Replace(User.Identity.Name.Substring(lgDash), "\", "")
0
 

Author Comment

by:crickpaolo
ID: 20007175
Nope. I get a blank on User.Identity.Name.

I did find another solution though. Here's my code:

Dim networklogon As String
Dim arrnetworklogon As Array
Dim loginname As String
       
'get network user data
networklogon = Request.ServerVariables("LOGON_USER")
arrnetworklogon = Split(networklogon, "\")
loginname = arrnetworklogon(UBound(arrnetworklogon)) 'extract the last part of the network logon

In order for it to work, I tweaked IIS and set the "Allow Anonymous Access" to false, and selected Windows security.

I will giving you the points though because you presented a possible alternative solution. I'm sure User.Identity.Name works, and I probably just had to modify the Web.config file, or some IIS parameters....
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question