Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
5bb2da32
Commit
5bb2da32
authored
Sep 22, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
页面修改
parent
c7ce787f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
5 deletions
+48
-5
IPHelper.cs
Mall.Common/Plugin/IPHelper.cs
+10
-0
ApiFilterAttribute.cs
Mall.WebApi/Filter/ApiFilterAttribute.cs
+17
-0
Startup.cs
Mall.WebApi/Startup.cs
+21
-5
No files found.
Mall.Common/Plugin/IPHelper.cs
View file @
5bb2da32
...
...
@@ -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
Mall.WebApi/Filter/ApiFilterAttribute.cs
View file @
5bb2da32
...
...
@@ -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
=
""
;
...
...
Mall.WebApi/Startup.cs
View file @
5bb2da32
...
...
@@ -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
(
newI
p
))
ip
=
context
.
Request
.
Headers
[
"X-Forwarded-For
"
].
FirstOrDefault
();
if
(
string
.
IsNullOrEmpty
(
i
p
))
{
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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment