Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Web API - Client IP Address

RSS
Modified on Mon, Jul 23, 2018, 9:13 AM by Administrator Categorized as ASP·NET MVC
Note that System.Net.Http.HttpRequestMessage is the Request object in any Web API controller.

private string GetUserHost(System.Net.Http.HttpRequestMessage request)
{
    const string key = "MS_HttpContext";

    if (!request.Properties.ContainsKey(key))
        return string.Empty;

    var context = request.Properties[key] as System.Web.HttpContextWrapper;

    return context?.Request.UserHostAddress ?? string.Empty;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.