Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i m using this code in controller but what should i do in corrosponding view to show a ip address in a web page

C#
public ActionResult Create()
       {
           //requesting ip IPAddress of machine
          string ipAddress = Request.ServerVariables["REMOTE_ADDR"];
          string ipAddress2 = Request.UserHostAddress;



           ViewBag.Org_id = new SelectList(db.Organizations, "ID", "Organization_name");
           ViewBag.Visitor_id = new SelectList(db.Visitors, "ID", "First_name");


           return View();
       }
Posted

1 solution

Controller;

ViewBag.IPAddress = ipAddress;


View;

Your IP is @ViewBag.IPAddress
 
Share this answer
 
Comments
R Mintri 16-Jul-15 9:03am    
i had tried but ip is showing is ::1?
is there any soution please provide according to mvc5
F-ES Sitecore 16-Jul-15 9:06am    
That is the correct result. ::1 is the ipv6 version of "locahost", or "127.0.0.1" in ipv4. If you want the ipv4 IP address then google "translate ipv6 to ipv4 c#"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900