Thursday, April 30, 2015

Get the IP Address of the thing poking at you in an ApiController in C#!

string ip = HttpContext.Current.Request.UserHostAddress;

 
 

Addendum 11/2/2015: On a similar note...

HttpContext.Current.Request.Browser.Browser

 
 

...will give you a friendly, simple name for the browser touching you, and if you set a breakpoint in the ApiController while debugging and then open the Immediate Window and type the following you will get a dump of all sort of facts about who is peering in your window from outside:

HttpContext.Current.Request

No comments:

Post a Comment