• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2193
  • Last Modified:

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.
0
shirleyz8821
Asked:
shirleyz8821
  • 3
  • 2
  • 2
1 Solution
 
DhaestCommented:
To get the UserName of the Authenticated User, but I doubt that this is the windows-user

HttpContext.Current.User.Identity.Name
0
 
DhaestCommented:
Mixing Forms and Windows Security in ASP.NET
http://msdn.microsoft.com/en-us/library/ms972958.aspx
0
 
Alan WarrenApplications DeveloperCommented:
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)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
shirleyz8821Author Commented:
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
0
 
Alan WarrenApplications DeveloperCommented:
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)
0
 
shirleyz8821Author Commented:
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?
0
 
Alan WarrenApplications DeveloperCommented:
I'd be inclined to suspect this one:
asp.net impersonation:Disabled
From memory, I think forms authentication or the aspnet_membership server impersonates the windows user.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now