Solved

Code not pulling user name from computer

Posted on 2009-05-04
10
375 Views
Last Modified: 2012-05-06
I am currently modifying one of my application to log the username from the computer.  Well, something in my code must be off because when I debug, it won't pull the user name.  Can someone please help me. Here's the string I use on my other applications but for some reason it's not working on this one.
strUserName = Mid(User.Identity.Name.ToString(), 11)

Open in new window

0
Comment
Question by:dlavar
  • 5
  • 3
10 Comments
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24297997
Is this an ASP application?  If so, you'll need to turn off Anonymous Access on the IIS site in order to capture the username.  With this enabled, the user isn't prompted to login (nor are credentials automatically passed if using IE with this option turned on).
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24298057
Your code is assuming that the hostname is 10 chars long, also User.Identity.Name is already a string, so no need for the ToString() method.

I'd suggest the following:
' User.Identity.Name = "Host\User"
Dim name As String = User.Identity.Name.Split("\"c)(1)

Open in new window

0
 

Author Comment

by:dlavar
ID: 24298062
Yes it is an ASP Application and how do you turn off the Anonymous Access off?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24298121
What version of IIS are you using?

Here are the instructions for IIS6:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/524404dc-8586-46b0-89ac-0f5db6d33c9c.mspx?mfr=true

Under IIS 5, you hit the properties of the site and then go to the authentication tab (or maybe directory security, I don't recall the exact name) and then they'll be a button or checkbox somewhere on that dialog to uncheck anonymous access.

When you turn this off, you're forcing users to login to the application, you'll need to enable Windows Authentication (or whatever mechanism you have in place) and users who are not setup to properly pass their credentials through to the webserver (users not on your network or who don't have your site in their trusted list) will be prompted to login.
0
 

Author Comment

by:dlavar
ID: 24298197
What if I don't want them to log on and just pull the user name?  Is that possible?
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24298250
If anonymous access is turned on, then IIS wont send a 401 in the headers of your request, which means the credentials wouldn't be sent from client to server, so you wouldn't have them.  If you only needed this on one or two pages, you could probably send the 401 in the header on that page, but if the user didn't have the option "Automatic Logon with Current Username and Password" setup in IE for the zone your site is in, they will be prompted.

Here's a ColdFusion example of how to send the header,
http://www.technicallychris.com/2006/09/12/getting-the-ntlm-info-with-anonymous-access-on/

... you'd need to modify (or have a more senior ASP person modify) it for .NET.  

To answer your question more directly, if you don't want them to log on, then they wont be logging on, but that means that there is no username for your to grab.
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24329058
I would like to know what your solution was (as I'm sure other EE members would) and have points assigned appropriately if the comments provided by myself or oobayly got you to your solution.
0
 

Accepted Solution

by:
dlavar earned 0 total points
ID: 24329184
For my solution, I went to the web configuration page and changed the following code.  Instead of allowing all users I closed that section and opened the deny users option.  When I did that I was able to pull the username although I'm not requiring them to log in.
<authorization>
			<!--allow users="*"/-->
			<!-- Allow all users -->
			<deny users="?"/>
			<!--  <allow     users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
                  <deny      users="[comma separated list of users]"
                             roles="[comma separated list of roles]"/>
            -->
		</authorization>

Open in new window

0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24329280
Awesome, I'm sure that will help someone out in the future :)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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