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
2a141709
Commit
2a141709
authored
Mar 16, 2022
by
黄奎
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开启限流策略
parent
01de4df8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
26 deletions
+26
-26
Startup.cs
Mall.WebApi/Startup.cs
+26
-26
No files found.
Mall.WebApi/Startup.cs
View file @
2a141709
...
...
@@ -128,32 +128,32 @@ namespace Mall.WebApi
}
return
ip
;
};
//
options.onIntercepted = (context, value, where) =>
//
{
//
var request = context.Request;
//
string ip = context.Request.Headers["X-Forwarded-For"].FirstOrDefault();
//
if (string.IsNullOrEmpty(ip))
//
{
//
ip = context.Connection.RemoteIpAddress.ToString();
//
}
//
Common.BackListHelper.Add(ip);
//
string uToken = "";
//
var parm = Helper.ApiTokenHelper.GetRequestParameters(request, ref uToken);
//
if (!string.IsNullOrEmpty(uToken))
//
{
//
var userInfo = Helper.ApiTokenHelper.ParsingToken(uToken);
//
if (userInfo != null && !string.IsNullOrEmpty(userInfo.uid))
//
{
//
Int32.TryParse(userInfo.uid, out int NewUserId);
// if (userInfo.requestFrom == Common.Enum.ApiRequestFromEnum.MiniProgram && NewUserId>
0)
//
{
//
UserReidsCache.Delete(userInfo.uid);
//
new EducationModule().UpdateUserBlacklist(NewUserId);
//
}
//
}
//
}
//
return new ApiThrottleResult() { Content = "访问过于频繁!" };
//
};
options
.
onIntercepted
=
(
context
,
value
,
where
)
=>
{
var
request
=
context
.
Request
;
string
ip
=
context
.
Request
.
Headers
[
"X-Forwarded-For"
].
FirstOrDefault
();
if
(
string
.
IsNullOrEmpty
(
ip
))
{
ip
=
context
.
Connection
.
RemoteIpAddress
.
ToString
();
}
Common
.
BackListHelper
.
Add
(
ip
);
string
uToken
=
""
;
var
parm
=
Helper
.
ApiTokenHelper
.
GetRequestParameters
(
request
,
ref
uToken
);
if
(!
string
.
IsNullOrEmpty
(
uToken
))
{
var
userInfo
=
Helper
.
ApiTokenHelper
.
ParsingToken
(
uToken
);
if
(
userInfo
!=
null
&&
!
string
.
IsNullOrEmpty
(
userInfo
.
uid
))
{
Int32
.
TryParse
(
userInfo
.
uid
,
out
int
NewUserId
);
if
(
userInfo
.
requestFrom
==
Common
.
Enum
.
ApiRequestFromEnum
.
MiniProgram
&&
NewUserId
>
0
)
{
UserReidsCache
.
Delete
(
userInfo
.
uid
);
new
EducationModule
().
UpdateUserBlacklist
(
NewUserId
);
}
}
}
return
new
ApiThrottleResult
()
{
Content
=
"访问过于频繁!"
};
};
});
}
...
...
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