Solved

Code not pulling user name from computer

Posted on 2009-05-04
10
374 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes it is an ASP Application and how do you turn off the Anonymous Access off?
0
 
LVL 13

Expert Comment

by:usachrisk1983
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:dlavar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Awesome, I'm sure that will help someone out in the future :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now