Commit 5bb2da32 authored by 黄奎's avatar 黄奎

页面修改

parent c7ce787f
......@@ -89,7 +89,17 @@ namespace Mall.Common.Plugin
return (userIp >= begin) && (userIp <= end);
}
public static bool CheckIPAddress(string str)
{
if (string.IsNullOrWhiteSpace(str) || str.Length < 7 || str.Length > 15)
return false;
string regformat = @"^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}{1}quot;";
Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
return regex.IsMatch(str);
}
}
}
\ No newline at end of file
......@@ -37,6 +37,23 @@ namespace Mall.WebApi.Filter
/// <param name="actionContext"></param>
public override void OnActionExecuting(ActionExecutingContext actionContext)
{
string ip = "";
ip = actionContext.HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip))
{
ip = actionContext.HttpContext.Connection.RemoteIpAddress.ToString();
}
if (!string.IsNullOrEmpty(ip) && Common.BackListHelper.bankList.Contains(ip))
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(new ApiResult
{
resultCode = (int)ResultCode.FormRepeatSubmit,
message = "傻屌",
data = null
});
Common.Plugin.LogHelper.Write("OnActionExecuting:" + ip);
}
//请求参数
JObject parm = new JObject();
string token = "";
......
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
......@@ -89,6 +90,12 @@ namespace Mall.WebApi
};
services.AddCors(options => options.AddPolicy("AllowCors", policy => policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins(corsArray.ToArray())));
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedFor
| Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto;
options.KnownProxies.Add(IPAddress.Parse("47.96.12.235"));
});
//services.AddCap(x =>
//{
// x.UseMongoDB(Common.Config.Mongo);
......@@ -145,12 +152,12 @@ namespace Mall.WebApi
options.OnIpAddress = (context) =>
{
string ip = "";
var newIp = context.Request.Headers["HTTP_X_FORWARDED_FOR"].FirstOrDefault();
if (string.IsNullOrEmpty(newIp))
ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip))
{
ip = context.Connection.RemoteIpAddress.ToString();
}
Common.Plugin.LogHelper.Write("ConfigureServices_Ip_【" + ip+"】");
Common.Plugin.LogHelper.Write("ConfigureServices_ip_【" + ip + "】");
return ip;
};
options.onIntercepted = (context, value, where) =>
......@@ -167,7 +174,14 @@ namespace Mall.WebApi
responseData = body.Result;
request.Body.Position = 0;
}
Common.Plugin.LogHelper.Write("ConfigureServices_responseData_【" + responseData + "】");
string ip = "";
ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip))
{
ip = context.Connection.RemoteIpAddress.ToString();
}
Common.BackListHelper.Add(ip);
Common.Plugin.LogHelper.Write("ConfigureServices_ip2222_【" + ip + "】");
if (!string.IsNullOrWhiteSpace(responseData.Trim()))
{
try
......@@ -192,7 +206,7 @@ namespace Mall.WebApi
UserReidsCache.Delete(uid.ToString());
new EducationModule().UpdateUserBlacklist(uid);
}
Common.Plugin.LogHelper.Write("ConfigureServices_Token_【" + json + "】");
}
}
catch (Exception ex)
......@@ -214,11 +228,13 @@ namespace Mall.WebApi
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
{
app.UseForwardedHeaders();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseApiThrottle();
app.UseHttpsRedirection();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment