client ip address in ASP.NET (.asmx) webservices

Posted by Zain Shaikh on Stack Overflow See other posts from Stack Overflow or by Zain Shaikh
Published on 2010-03-28T19:47:21Z Indexed on 2010/03/28 19:53 UTC
Read the original article Hit count: 524

Filed under:
|
|

I am using ASP.Net (.asmx) web services with Silverlight. since there is no way to find client ip address in Silverlight, therefore I had to log this on service end. these are some methods I have tried:

Request.ServerVariables(”REMOTE_HOST”) HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; Request.UserHostAddress() Request.UserHostName() string strHostName = System.Net.Dns.GetHostName(); string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();

All the above methods work fine on my local system, but when I publish my service on production server. it starts giving errors.

Error: Object reference not set to an instance of an object. StackTrace: at System.Web.Hosting.ISAPIWorkerRequestInProc.GetAdditionalServerVar(Int32 index) at System.Web.Hosting.ISAPIWorkerRequestInProc.GetServerVariable(String name) at System.Web.Hosting.ISAPIWorkerRequest.GetRemoteAddress() at System.Web.HttpRequest.get_UserHostAddress()

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about web-services