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.Sp lit('\\')[ 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.
Here is the code:
//get windows user name without domain name
string windowsUserName = WindowsIdentity.GetCurrent
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.
</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.
Mixing Forms and Windows Security in ASP.NET
http://msdn.microsoft.com/en-us/library/ms972958.aspx
http://msdn.microsoft.com/en-us/library/ms972958.aspx
Hi shirleyz8821,
things you could try:
things you could try:
username = Login1.UserName
username = My.User.Name
username = Profile.UserName
username = HttpContext.Current.User.Identity.Name
username = Membership.GetUser.UserName
Alan ";0)
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.I dentity.Na me & Login1.UserName etc is returning test rather than windows user ID
user name: test
password:test
IIS configuration:
Anonymous access: Enabled
asp.net impersonation:Disabled
Forms Authentication:Enabled
HttpContext.Current.User.I
Usefull links:
http://stackoverflow.com/questions/6748976/get-windows-username-in-asp-net-without-system-web
http://forums.asp.net/t/1045923.aspx
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;
Alan ";0)
ASKER
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?
asp.net impersonation:Disabled
Forms Authentication:Enabled?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
HttpContext.Current.User.I