[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-08-21
7
Medium Priority
?
1,897 Views
Last Modified: 2012-10-17
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
Comment
Question by:shirleyz8821
  • 3
  • 2
  • 2
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 38319260
To get the UserName of the Authenticated User, but I doubt that this is the windows-user

HttpContext.Current.User.Identity.Name
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 38319261
Mixing Forms and Windows Security in ASP.NET
http://msdn.microsoft.com/en-us/library/ms972958.aspx
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38319880
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:shirleyz8821
ID: 38321586
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
 
LVL 26

Expert Comment

by:Alan Warren
ID: 38322895
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
 

Author Comment

by:shirleyz8821
ID: 38325693
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
 
LVL 26

Accepted Solution

by:
Alan Warren earned 1500 total points
ID: 38327436
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question