Asp.net WEB Project C # method for reading domain usernames
BS internal management system, because the other company uses domain management, so you want the system to automatically log on based on the Windows domain user.
It took a lot of effort to do this. Because our company does not have a Domain Server, we have a temporary one. (By The Way, Windows Server 2003 domain servers can be set up at any time, you don't have to select a Domain Server for installation like Windows 2000, so I don't need to format the system.-_-|) I checked a lot of information online, after practice, I finally came up with a method. In fact, many methods can be written on the Internet, but I just clicked it and I cannot understand it in some places.
Make a summary and note for future use:
(1) environment requirements: the IIS server must be in the domain. It should be IIS installed under the domain user. I have a computer that originally had IIS installed, I directly added my computer to the domain and used the original IIS as the server. I found that it was not working and cannot manage IIS. Although it can be used, the login window will pop up during access, if anonymous users are allowed, the domain user name cannot be read.
(2) system settings: If IIS is set to "Directory Security", "anonymous" access is removed and "Integrated windows Identity Authentication" is adopted; in. net system, Web. config
<! --
In the <authentication> section, you can configure
Security Authentication mode,
To identify the user.
-->
<Authentication mode = "Windows"/>
Use the Windows demonstration method.
(3)Code:
User. Identity. Name; // read domain login username in the format of domainname \ USERNAME (Domain Name \ User Name)
Someone on the Internet said that the user name can be read using system. environment. Username; I found that the user name can be read locally. The web service is not good, and the domain is not good.
The following code reads the full name of the domain where the server is located:
Iphostentry myhost = new iphostentry ();
Myhost = DNS. gethostbyname (DNS. gethostname ());
This. labhost. Text = myhost. hostname. tostring ();
Result: server.domain.sobnb.com
(4) Conclusion: for access by domain users, all environments must be carried out in the domain. In non-domain environments, Web servers should not read the Windows user information of the client (the client's JS Code is acceptable ), it should be said that the user name in the domain reads the information in the Domain Server, not the client information. Do not know if this is true?
In fact, this function is very useful. If you are an enterprise management system of BS, this is really good. First, it is convenient, you do not need to log on; second, it is secure; third, it is easy to manage.
From: http://blog.sobnb.com/u/92/6150.html