I am having some major issues when it comes to getting the current username of the account signed on using Asp.Net's default logging system and WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)
seems to work correctly.
The problem is a non-issue when debugging locally, but now I am at a point where I am deploying to IIS. I have tested several ways to get the logged in user, but to no avail. What I have tried are:
System.Web.HttpContext.Current.User.Identity.Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name
System.Environment.UserName
HttpContext.Current.Request.LogonUserIdentity.Name
WebSecurity.CurrentUserName
With Results -
CORP\\bsmith
IIS APPPOOL\\SecondaryAppTest
SecondaryAppTest
CORP\\bsmith
CORP\\bsmith
None of these are the username of the successful logged in individual username "aaa@gmail.com"
I have also updated my web.config to set impersonation to false and authentication mode to forms as well as windows.
Can anyone tell me how to get the correct username, provided a successful login when deployed to IIS?
Thank you very much.
I hope this link can be your solution or
if you open your _LoginPartial.cshtml under Views/Shared folder you will get following " User.Identity.GetUserName() " which give login in user name.
if you deploy on iis and you config the webconfig <authentication mode="Windows"/>
you will get the computer name. But if you set in your application a Anonymous access to disabled and only Integrated Windows Authentication in IIS you get user account run the asp.net and if you add <identity impersonate ="true"/>
i think you get the window account name i read it somewhere just dont remember where is the post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.