42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace GPW.CORE6.Smart.Controllers
|
|
{
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class InfoController : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Controller epr recuperare l'IP del chiamante
|
|
///
|
|
/// rif: https://bartecki.me/blog/Blazor-serverside-get-remote-ip
|
|
/// https://stackoverflow.com/questions/57982444/how-do-i-get-client-ip-and-browser-info-in-blazor
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[Route("ipaddress")]
|
|
public async Task<string> GetIpAddress()
|
|
{
|
|
var remoteIpAddress = this.HttpContext.Request.HttpContext.Connection.RemoteIpAddress;
|
|
await Task.Delay(1);
|
|
if (remoteIpAddress != null)
|
|
return remoteIpAddress.ToString();
|
|
return string.Empty;
|
|
/*
|
|
Per impiegarlo aggiungere in Host.cshtml
|
|
<script>
|
|
window.getIpAddress = () => {
|
|
return fetch('/api/info/ipaddress')
|
|
.then((response) => response.text())
|
|
.then((data) => {
|
|
return data
|
|
})
|
|
}
|
|
</script>
|
|
*/
|
|
}
|
|
|
|
|
|
}
|
|
}
|