views:

2153

answers:

3

Is there a way to get the IP address of a client in Silverlight if my Silverlight control is hosted in HTML?

A: 

Try the methods listed below (first one should usually do the trick), or see here for more info.

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();
Chris Ballance
this is not for html.. its parameter passing in case of Asp.net.. this is not possible from HTML to my knowledge
Usman Masood
@Chris I have tried all the methods, 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. all the above methods work fine on my local system, but when i publish my service on production server. it starts giving errors.
Zain Shaikh
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()
Zain Shaikh
+2  A: 

As far as I know there are no direct ways to do this. May be you can create a WebMethod to achieve this. Or some other tricks.

Check this thread, there are some suggestions: http://silverlight.net/forums/t/34744.aspx

NinethSense
yep! i knew about webservice method idea.... but i thought may be there is any other workaround....
Usman Masood
No direct work around in my knowledge.
NinethSense
But what is your opnion why this is a limitation in silverlight?
Usman Masood
+1  A: 

I have found this website provides a lot of ways to detect visitors' IP address - http://www.ip2location.com/developers.aspx . Not sure can helping on Silverlight or not. I'm also looking forward to detect my web visitors' IP address and to displaying their geographical location.

hexahow