views:

196

answers:

3

Is there a way to get the logged in user from a vb.net web application? IE, if someone logged in as "foo"/"bar" on their local machine accesses the site, I need code to get me "foo"/"bar". This is for a passthrough on our intranet, where everyone uses the same Active Directory.

Essentially, I need to harvest the username of the logged in user and check it against our ActiveDirectory instance. If that fails, I need to check for Request variables and check those (that part is fairly easy). Then if THAT fails, I need to show a login screen (I also have a handle on this).

I've already come across and discarded a couple solutions for the part I'm having trouble with:

  1. request.serverVariables("LOGON_USER") - This only works if you have anonymous access turned off in IIS, and that must be on to use forms authentication (which I'm using).
  2. http://www.thescarms.com/dotnet/IsInRole.aspx - This solution does not seem to work for some reason. I suspect the line AppDomain.CurrentDomain.SetPrincipalPolicy( Principal.PrincipalPolicy.WindowsPrincipal) is the issue, but the meaning of this line is buried so far I can't figure out what it's actually trying to do.
+1  A: 

HttpRequest.LogonUserIdentity?

Arnshea
You'll need to have authentication turned on otherwise it'll always be the anonymous/default user.
Arnshea
+1  A: 

if you're using Forms Authentication, have you tried System.Web.HttpContext.Current.User.Identity.Name?

Jason
Not yet. I think Current.User will be what I need, but I need to look a little more. Thanks for the idea!
of course! you can also do Current.User.IsInRole("somerole") to find out what their role is (if you set roles).
Jason
A: 

The web browser will not send the user's local credentials to the web server unless two things are true:

  • The web server asks for them (i.e. Anonymous Access is disabled, and Windows Integrated Authentication is enabled).
  • The web browser has been configured to send local credentials if asked (an Internet Explorer option, available in FireFox via plugin, not sure about other browsers). If the browser has not been configured to send the information and the web server asks, the user will be prompted within a pop-up login screen.
chyne