Gal Ratner
Gal Ratner is a Techie who lives and works in Los Angeles CA and Austin TX. Follow galratner on Twitter Google
How to get the port number of a remote HTTP request

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
Filed under:

Powered by Community Server (Non-Commercial Edition), by Telligent Systems