views:

253

answers:

5

I'm creating an intranet web-application in an IE shop and I'm looking to retrieve the user's logged-in computer username without prompting for a username/password combination. This is easy, until the application is placed on a webserver. It seems that every combination I try from here on in results in either a null string or prompting for login information.

I have defined:

 <authentication mode="Windows"/>
 <identity impersonate="true"/>

And I'm trying these options:

Response.Write("HttpContext: " & HttpContext.Current.User.Identity.Name & " \n")
Response.Write("Windows Identity: " & WindowsIdentity.GetCurrent.Name & " \n")
Response.Write("Thread: " & Thread.CurrentPrincipal.Identity.Name & " \n")
Response.Write(Request.ServerVariables("LOGON_USER"))
Response.Write(User.Identity.Name)

None of these with any combination of IIS settings seems to be working for me. Have I taken the wrong approach? Is this possible? How can I solve this?

Whenever I switch my IIS to use Windows Integrated Authentication, it prompts me for a username/password. Why is this? How can I stop it?

An example of what I want (if it's not clear), is

DOMAINNAME/USERNAME or HOME/CHARLIE

+1  A: 

I think you may want to set up the web site to use Integrated Windows Authentication.

Fredrik Mörk
+1  A: 

Impersonation and delegation is a tricky beast. In your case, you need to use Integrated Authentication for your web site, at the least.

See this article on MSDN about impersonation and delegation for more information

Philip Rieck
Integrated Authentication forces a prompt for username/password, no?
Mark
Depends on browser/network configuration. See Dylan Beattie's response for more info
Philip Rieck
A: 

Also make sure that in IE, the setting "Enable Integrated Windows Authentication" is enabled.

Jonas
in IE? Or IIS? This is stated at the bottom of my description, or have I missed something
Mark
In IE...if that setting is off, you'll get prompted for your credentials regardless. It's just another thing to make sure of. :)
Jonas
+2  A: 

Make sure that the server(s) that host your application are in the Intranet zone under IE's security settings; by default, IE doesn't automatically send Windows authentication credentials to sites in other zones. You may also need to add your site's hostname(s) to the Trusted sites zone.

If your website is something like intranet.mydomain.com and your users are authenticating against an Active Directory server for mydomain.com, this will happen automatically; otherwise, you'll need to modify IE's settings, or host your app on a server that's a member of your Active Directory domain.

Dylan Beattie
A: 

Basically make sure the users IE browser in your domain will authenticate the user without prompting them. It is a client browser setting issue.

ctrlShiftBryan
What do you mean it is a client browser setting issue? It's not the client's browser that is asking for their username and password. It is the application and its settings. I'm not sure what you mean.
Mark
The browser is prompting the user for authentication as opposed to auto logging them in. As other have said make sure "Enable Integrated Windows Authentication" is enabled
ctrlShiftBryan