修复域名转发获取ip地址长度过长问题。

pull/80/head
JianWeie 4 years ago
parent 059a282522
commit 584f15d39f

@ -95,7 +95,10 @@ namespace CoreCms.Net.Middlewares
var ip = context.Request.Headers["X-Forwarded-For"].ObjectToString();
if (string.IsNullOrEmpty(ip))
{
ip = context.Connection.RemoteIpAddress.ObjectToString();
if (context.Connection.RemoteIpAddress != null)
{
ip = context.Connection.RemoteIpAddress.MapToIPv4().ObjectToString();
}
}
return ip;
}

@ -409,7 +409,8 @@ namespace CoreCms.Net.Services
billPayments.type = type;
billPayments.status = (int)GlobalEnumVars.BillPaymentsStatus.NoPay;
billPayments.paymentCode = paymentCode;
billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
billPayments.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
billPayments.parameters = @params != null ? JsonConvert.SerializeObject(@params) : "";
billPayments.createTime = DateTime.Now;

@ -385,7 +385,7 @@ namespace CoreCms.Net.Services
formSubmitModel.payStatus = false;
formSubmitModel.status = false;
formSubmitModel.createTime = DateTime.Now;
formSubmitModel.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
formSubmitModel.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
var formSubmitId = await _formSubmitServices.InsertReturnIdentityAsync(formSubmitModel);

@ -87,7 +87,7 @@ namespace CoreCms.Net.Services
oldLog.code = type;
oldLog.createTime = DateTime.Now;
oldLog.mobile = mobile;
oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
oldLog.isUsed = false;
var obj = new
{
@ -238,7 +238,8 @@ namespace CoreCms.Net.Services
oldLog.parameters = JsonConvert.SerializeObject(parameters);
oldLog.contentBody = str;
oldLog.createTime = DateTime.Now;
oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
oldLog.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
oldLog.isUsed = isUsed;
await _dal.InsertAsync(oldLog);

@ -532,7 +532,7 @@ namespace CoreCms.Net.Services
order.orderDiscountAmount = cartDto.orderPromotionMoney > 0 ? cartDto.orderPromotionMoney : 0;
order.goodsDiscountAmount = cartDto.goodsPromotionMoney > 0 ? cartDto.goodsPromotionMoney : 0;
order.couponDiscountAmount = cartDto.couponPromotionMoney;
order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
order.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
//以上保存了订单主体表信息,以下生成订单明细表
var items = FormatOrderItems(cartDto.list, order.orderId);
if (!items.Any())

@ -630,7 +630,8 @@ namespace CoreCms.Net.Services
var log = new CoreCmsUserLog();
log.userId = userInfo.id;
log.state = isReg ? (int)GlobalEnumVars.UserLogTypes. : (int)GlobalEnumVars.UserLogTypes.;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.createTime = DateTime.Now;
log.parameters = isReg ? GlobalEnumVars.UserLogTypes..ToString() : GlobalEnumVars.UserLogTypes..ToString();
await _userLogServices.InsertAsync(log);

@ -137,7 +137,9 @@ namespace CoreCms.Net.Web.Admin.Controllers
//插入登录日志
var log = new SysLoginRecord();
log.username = model.userName;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.os = RuntimeInformation.OSDescription;
if (_httpContextAccessor.HttpContext != null)
log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent];
@ -152,7 +154,9 @@ namespace CoreCms.Net.Web.Admin.Controllers
//插入登录日志
var log = new SysLoginRecord();
log.username = model.userName;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.os = RuntimeInformation.OSDescription;
if (_httpContextAccessor.HttpContext != null)
log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent];
@ -212,7 +216,9 @@ namespace CoreCms.Net.Web.Admin.Controllers
if (_httpContextAccessor.HttpContext != null)
{
if (_httpContextAccessor.HttpContext.Connection.RemoteIpAddress != null)
{
log.ip = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
}
log.os = RuntimeInformation.OSDescription;
log.browser = _httpContextAccessor.HttpContext.Request.Headers[HeaderNames.UserAgent];
}

@ -208,7 +208,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
var log = new CoreCmsUserLog();
log.userId = user.id;
log.state = (int)GlobalEnumVars.UserLogTypes.;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.createTime = DateTime.Now;
log.parameters = GlobalEnumVars.UserLogTypes..ToString();
await _userLogServices.InsertAsync(log);
@ -316,7 +316,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers
var log = new CoreCmsUserLog();
log.userId = user.id;
log.state = (int)GlobalEnumVars.UserLogTypes.;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.createTime = DateTime.Now;
log.parameters = GlobalEnumVars.UserLogTypes..ToString();
await _userLogServices.InsertAsync(log);
@ -522,7 +522,9 @@ namespace CoreCms.Net.Web.WebApi.Controllers
var log = new CoreCmsUserLog();
log.userId = id;
log.state = (int)GlobalEnumVars.UserLogTypes.;
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString() : "127.0.0.1";
log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ?
_httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1";
log.createTime = DateTime.Now;
log.parameters = GlobalEnumVars.UserLogTypes..ToString();
await _userLogServices.InsertAsync(log);

Loading…
Cancel
Save