I want to get ip address of client in static class
in asp.net mvc 3
.
But i can't access request object in static class.
can any one help how to get ip address without request object in static class??
You can get the user's IP address in a static class like this:
string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
{
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
return ip;
This technique is better to use that Request.UserHostAddress() as that will sometimes only capture the IP address of a user's proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With