Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Code not pulling user name from computer

Posted on 2009-05-04
10
Medium Priority
?
380 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Screencast - Getting to Know the Pipeline

916 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