李昊 4 years ago
parent
commit
f326db2a84

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminController.cs

@@ -37,6 +37,7 @@ namespace GxPress.Api.AdminControllers
             _logger = logger;
             _adminRepository = adminRepository;
             this.roleService = roleService;
+            this.httpContextAccessor=httpContextAccessor;
         }
 
         /// <summary>
@@ -48,7 +49,7 @@ namespace GxPress.Api.AdminControllers
         [AllowAnonymous]
         public async Task<AdminSignInResult> SignIn(AdminSignInRequest request)
         {
-            request.Ip = httpContextAccessor.HttpContext.Connection.LocalIpAddress.ToString();
+            request.Ip = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
             var result = await _adminRepository.SignInAsync(request);
             //获取菜单
             result.MenuInResult = await roleService.GetMenusAllAsync(result.RoleId);

+ 2 - 0
gx_api/GxPress/Api/GxPress.Api/Startup.cs

@@ -4,6 +4,7 @@ using GxPress.Common.Middleware;
 using GxPress.Common.Tools;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Http.Features;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.Extensions.Configuration;
@@ -28,6 +29,7 @@ namespace GxPress.Api
         // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
         public void ConfigureServices(IServiceCollection services)
         {
+             services.AddSingleton<IHttpContextAccessor,HttpContextAccessor>();
             services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
             services.AddControllers().AddNewtonsoftJson(options =>
             {