开发者

How to get the user machine's login name?

开发者 https://www.devze.com 2023-04-12 09:44 出处:网络
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,

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号