Hey how do you get the remote port for a request on the web server?
So my code should look like this:
public class EndpointReflectionHandler : IHttpHandler
{
public new void ProcessRequest(HttpContext context)
{
string address = context.Request.UserHostAddress;
int port = context.Request.UserHostPort; //it's not there
context.Response.ContentType = "text/plain";
context.Response.Write(address + ":" + port);
}
}
..but I can't find anything to get the port.
EDIT. Thanks to Tim for great comment:
Here's the full workflow:
- Client starts, opens a socket
- Hey webservice what's my IP and port?
- It's 1.2.3.4:1234
- Hey other person, I'll listen on 1.2.3.4:1234 (even though to me it looks like 9.9.9.9:9999
- OK man I'll connect to 1.2.3.4:1234
- Everyone happy, have a beer
I got it context.Request.ServerVariables["REMOTE_PORT"].
There's nothing about it, just guesswork and looking everywhere :)