In order to get the remote port of an http request we need to work with HttpWorkerRequest.
HttpWorkerRequest is a low level class used by HttpContext. Its main function is to define the base worker methods used by ASP.NET managed code in order to process HTTP requests.
Now let’s leverage it In order to find out the remote client’s port:
IServiceProvider provider = (IServiceProvider)HttpContext.Current;
HttpWorkerRequest worker = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
//The client's HTTP port number.
int remotePort = worker.GetRemotePort();
Simple isnt it?
Posted
24 Oct 2009 10:06 AM
by
Gal Ratner