Link to home
Start Free TrialLog in
Avatar of shirleyz8821
shirleyz8821

asked on

ASP.NET Get Windows Domain User ID in IE when using Forms authentication

In asp net 4.0, I cannot get windows username on form's authentication.

Here is the code:
           //get windows user name without domain name
            string windowsUserName = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
It is correct in debug mode but get the application name after publishing to IIS.

Here is the web.config:
    <authentication mode="Forms">      
      <forms loginUrl="~/Account/Login.aspx" protection="All" defaultUrl="Default.aspx" timeout="30" />
    </authentication>

This web application access is based on a security table permission rather than windows authentication. How to get the user's window ID when user is browsing the app.

Thanks in advance.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

To get the UserName of the Authenticated User, but I doubt that this is the windows-user

HttpContext.Current.User.Identity.Name
Mixing Forms and Windows Security in ASP.NET
http://msdn.microsoft.com/en-us/library/ms972958.aspx
Hi shirleyz8821,
things you could try:
    username = Login1.UserName
    username = My.User.Name
    username = Profile.UserName
    username = HttpContext.Current.User.Identity.Name
    username = Membership.GetUser.UserName

Open in new window

Alan ";0)
Avatar of shirleyz8821
shirleyz8821

ASKER

I have account not domain name:
user name: test
password:test
IIS configuration:
Anonymous access: Enabled
asp.net impersonation:Disabled
Forms Authentication:Enabled


HttpContext.Current.User.Identity.Name & Login1.UserName etc is returning test rather than windows user ID
Usefull links:
http://stackoverflow.com/questions/6748976/get-windows-username-in-asp-net-without-system-web
http://forums.asp.net/t/1045923.aspx
using System.Threading;

string userName = Thread.CurrentPrincipal.Identity.Name;

Open in new window

Alan ";0)
Thanks Alan, tried your methods still unable to get windos ID, is it because the IIS configuration: Anonymous access: Enabled
asp.net impersonation:Disabled
Forms Authentication:Enabled?
ASKER CERTIFIED SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial