In the modification of the student, when the IP is really not, has been used in the previous method, appeared to show the wrong.
I have used many methods to test:
viewdata["IP"] = Request.UserHostAddress.ToString (); Local IP dynamic get:: 1 //viewdata["IP"] = System.Web.HttpContext.Current.Request.UserHostAddress.ToString ();// Local IP dynamic get:: 1 //viewdata["IP"] = httpcontext.current.request.servervariables["REMOTE_ADDR"];//missing reference, no validation viewdata["IP"] = Request.System.Web.HttpContext.Current.Request.UserHostAddress.ToString ();//Missing reference, no validation viewdata["IP"] = request.servervariables["REMOTE_ADDR"]. ToString (); Local IP dynamic Get get::1</span></span>
The number I took out :1, is the representation of the local loopback address under IPv6. It is normal for you to access it using localhost. The use of IP address access or shutdown IPv6 support can not display this. Finally, I changed a way to achieve IP access to the LAN :
Read the name of the computer string pcname = System.Net.Dns.GetHostName (); Get the native LAN IP address //ipaddress localaddress = dns.gethostaddresses (name) [0]; IPAddress LocalAddress1 = Dns.gethostbyname (pcname). addresslist[0];//This sentence verification can be used //IPAddress dynaddress = Dns.gethostbyname (pcname). ADDRESSLIST[0];
The result is:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Get computer name (HostName) and IP address (Addresses)