Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get User IP in ASP.NET MVC API Controller

I have tried the Request.UserHostAddress; but API controller doesn't have UserHostAddress inside Request.

like image 324
user1615362 Avatar asked Sep 26 '12 18:09

user1615362


2 Answers

IP = ((HttpContextBase)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
like image 170
Sando Avatar answered Oct 02 '22 18:10

Sando


I am using the following code and it work for me....

string ipAddress =   System.Web.HttpContext.Current.Request.UserHostAddress;
like image 29
Md. Nazrul Islam Avatar answered Oct 02 '22 17:10

Md. Nazrul Islam