Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Code not pulling user name from computer

Posted on 2009-05-04
10
Medium Priority
?
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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