From 9591a0ac6732a484aee0874d8ab302909c22b0e8 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 1 Feb 2017 03:50:44 +0100 Subject: [PATCH] api/myip --- Yavsc/ApiControllers/AccountController.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Yavsc/ApiControllers/AccountController.cs b/Yavsc/ApiControllers/AccountController.cs index 68a6c912..6a154684 100644 --- a/Yavsc/ApiControllers/AccountController.cs +++ b/Yavsc/ApiControllers/AccountController.cs @@ -13,6 +13,7 @@ namespace Yavsc.WebApi.Controllers using Models.Auth; using Yavsc.Helpers; using System; + using System.Linq; [Authorize(),Route("~/api/account"),Obsolete] public class ApiAccountController : Controller @@ -141,6 +142,24 @@ namespace Yavsc.WebApi.Controllers return Ok(user); } + [HttpGet("~/api/myip"),Authorize] + public async Task MyIp () + { + string ip = null; + + ip = Request.Headers["X-Forwarded-For"]; + + if (string.IsNullOrEmpty(ip)) { + ip = Request.Host.Value; + } else { // Using X-Forwarded-For last address + ip = ip.Split(',') + .Last() + .Trim(); + } + + return Ok(ip); + } + /// /// Actually only updates the user's name. ///