I'm developing a system in ASP.NET which needs user authentication. The authentication system should look up to the login name in the user machine instead of typing the username in the textbox. Then, if it's regi开发者_运维百科stred in the database, it should log in automatically.
How do I get, by code, the user machine's login name?
You can use:
User.Identity.Name
This is found in the HttpContext.User
Property.
Try a couple of these options:
Request.ServerVariables("LOGON_USER")
Request.ServerVariables("REMOTE_USER")
Request.ServerVariables("AUTH_USER")
Unless this is an intranet application and you're using Windows Authentication, there is no way to get that information.
If you enable Windows Authentication, the user will be prompted to enter their domain credentials, after which you'll be able access their username like this:
string userName = User.Identity.Name;
精彩评论