views:

146

answers:

4

Hi

I have a website with a large user base configured with asp.net 2.0 forms authentication. Before the user logs in via forms authentication is it possible to retrieve the windows login name/user account name on the machine they are using?

Many thanks

A: 

Not BEFORE no (not from the server).

Depending on the type of Auth you use, though, and the way the site is configured, you CAN get them to log in with their windows details.

Noon Silk
+1  A: 

Unfortunately no - if the user has not logged on, they are browsing anonymously, and are therefore unknown to the server. There is no way to identify them.

Once they're logged on, if you're using impersonation use WindowsIdentity.GetCurrent().Name. However, for forms authentication there's no direct way to ask the browser for their Windows credentials as they may not even be running Windows!

Jeremy McGee
Many thanks. Actually it does not matter if it is before or after login, I just need to know the client os username. After forms login WindowsIdentity.GetCurrent().Name returns nt authority/network service. So I assume this is not possible without some kind of activeX control. Thanks for the help.
Shigg
Indeed, I (incorrectly) assumed you were using impersonation - I've updated my answer.
Jeremy McGee
Shigg: Actually, it is possible, if your site is in the trusted zone and using windows auth.
Noon Silk
+1  A: 

This would only be possible if you were using Windows Authentication in your web application and then only if the user had logged in.
The kind of information you are after is not sent as part of the web request (quite rightly) and is therefore unknown to the web server.

Andy Rose
+1  A: 

It certainly is possible--by adding another web application to your system. Here's roughly how I have done it:

Your primary web app uses Forms authentication. On the forms login page, any user that is determined to be on the local LAN (check IP address), redirect them to another app that uses Windows authentication. In this second app, you can determine the user (assuming the browser is configured to send credentials automatically to the zone in which your app resides), then set a cookie which your first app can read, and redirect the user back to the original app.

This does work.

TheObjectGuy
How do you set the cross-app cookie?
awe