api/myip
This commit is contained in:
parent
43d3231ccf
commit
cc04eaed65
1 changed files with 19 additions and 0 deletions
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue