feat: Add IPAddress.ToIPv4String method

This commit is contained in:
Argo Zhang 2019-06-25 00:12:37 +08:00
parent 484e00f677
commit ea2fe0f536
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
6 changed files with 9 additions and 9 deletions

View File

@ -71,7 +71,7 @@ namespace Bootstrap.Admin.Controllers
{
loginUser.UserAgent = context.Request.Headers["User-Agent"];
var agent = new UserAgent(loginUser.UserAgent);
loginUser.Ip = (context.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
loginUser.Ip = context.Connection.RemoteIpAddress.ToIPv4String();
loginUser.City = ipLocator.Locate(loginUser.Ip);
loginUser.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
loginUser.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
@ -94,4 +94,4 @@ namespace Bootstrap.Admin.Controllers
[ResponseCache(Duration = 600)]
public ActionResult AccessDenied() => View("Error", ErrorModel.CreateById(403));
}
}
}

View File

@ -37,7 +37,7 @@ namespace Bootstrap.Admin.Controllers.Api
{
value.UserAgent = Request.Headers["User-Agent"];
var agent = new UserAgent(value.UserAgent);
value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
value.Ip = HttpContext.Connection.RemoteIpAddress.ToIPv4String();
value.Browser = $"{agent.Browser?.Name} {agent.Browser?.Version}";
value.OS = $"{agent.OS?.Name} {agent.OS?.Version}";
value.City = ipLocator.Locate(value.Ip);
@ -45,4 +45,4 @@ namespace Bootstrap.Admin.Controllers.Api
return LogHelper.Save(value);
}
}
}
}

View File

@ -48,7 +48,7 @@ namespace Bootstrap.Admin.Controllers.Api
[AllowAnonymous]
public bool Put()
{
var ip = (Request.HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString();
var ip = Request.HttpContext.Connection.RemoteIpAddress.ToIPv4String();
if (_loginUsers.TryGetValue(ip, out var user))
{
user.Reset();

View File

@ -8,7 +8,7 @@
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.5" />
<PackageReference Include="Longbow.Cache" Version="2.2.12" />
<PackageReference Include="Longbow.Data" Version="2.3.2" />
<PackageReference Include="Longbow.Web" Version="2.2.13" />
<PackageReference Include="Longbow.Web" Version="2.2.14" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
</ItemGroup>

View File

@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.9" />
<PackageReference Include="Longbow.Configuration" Version="2.2.3" />
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

View File

@ -7,9 +7,9 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.5" />
<PackageReference Include="Longbow.Data" Version="2.3.2" />
<PackageReference Include="Longbow.Logging" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.8" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Web" Version="2.2.13" />
<PackageReference Include="Longbow.Web" Version="2.2.14" />
<PackageReference Include="Longbow.Cache" Version="2.2.12" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.4" />
<PackageReference Include="PetaPoco.Extensions" Version="1.0.5" />