Get the current HTTP context:
If you do this in the MVC controller, you can directly use the controller property HttpContext .
var context = HttpContext.Current as IServiceProvider;
Next, get an HTTP workstation request:
var request = context.GetService( typeof(HttpWorkerRequest)) as HttpWorkerRequest;
Then you can get the client ephemeral number as follows:
var port = request.GetRemotePort();
source share