How to know IPAddress of particular user in Views in MVC

Posted by Manideepgoud under ASP.NET MVC on 2/18/2017 | Points: 10 | Views : 1544 | Status : [Member] | Replies : 1
I have created IPAddress in table in Sqlserver, how to display IPAddress of particular user after creating message in view.


Posted by: Rajnilari2015 on: 2/19/2017 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

@Manideepgoud Sir, please try this

public ActionResult currentUserIPAddress()
var currentUserId = User.Identity.GetUserId();
var currentUser = db.Users.FirstOrDefault(x => x.Id == currentUserId);
var currentUserIPAddress = (from record in <YOUR TABLE>
where record.ApplicationUser == currentUser
select record.IPAddressColumn).ToList();
return View(currentUserIPAddress);


Hope that helps.

Thanks & Regards,
RNA Team

Manideepgoud, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response