简体   繁体   中英

get ip address (when no ASP.NET available (on linux server))

I can't find the ip address without the aspx page (so on a linux server). If it can work through wcf then its also good.

I think your best bet is to let a web service return the IP address to the Silverlight client if you are able to use WCF in your application. I don't believe there is any straightforward way to get the client IP directly within Silverlight.

Just a simple web method like this should work:

[OperationContract]
public string GetClientIpAddress()
{
    return HttpContext.Current.Request.UserHostAddress;
}

You might not be able to get the actual client IP address if the request is going through a proxy server, but you could check the HTTP_X_FORWARDED_FOR header as well and use that if available.

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

I wouldn't depend on that as a reliable client IP address though, since not all proxy servers honor that HTTP header and it could also be easily spoofed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM