api/myip
This commit is contained in:
@ -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<IActionResult> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Actually only updates the user's name.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user