Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Education
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
黄奎
Education
Commits
0dcb5b00
Commit
0dcb5b00
authored
Jan 21, 2021
by
黄奎
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://gitlab.oytour.com/Kui2/education
parents
f8e00fe7
9e3dd12d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
16 deletions
+36
-16
AllowRepeatAttribute.cs
Edu.WebApi/Filter/AllowRepeatAttribute.cs
+13
-0
ApiFilterAttribute.cs
Edu.WebApi/Filter/ApiFilterAttribute.cs
+23
-16
No files found.
Edu.WebApi/Filter/AllowRepeatAttribute.cs
0 → 100644
View file @
0dcb5b00
using
System
;
namespace
Edu.WebApi.Filter
{
/// <summary>
/// 允许重复提交表单属性
/// </summary>
public
class
AllowRepeatAttribute
:
Attribute
{
}
}
\ No newline at end of file
Edu.WebApi/Filter/ApiFilterAttribute.cs
View file @
0dcb5b00
...
...
@@ -12,6 +12,7 @@ using Edu.Common.Plugin;
using
Edu.Common.API
;
using
Edu.Cache.User
;
using
Edu.WebApi.Helper
;
using
System.Reflection
;
namespace
Edu.WebApi.Filter
{
...
...
@@ -43,31 +44,37 @@ namespace Edu.WebApi.Filter
}
#
region
验证表单重复提交
string
controllerName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"controller"
].
ToString
().
ToLower
();
string
actionName
=
actionContext
.
ActionDescriptor
.
RouteValues
[
"action"
].
ToString
().
ToLower
();
var
action
=
actionContext
.
ActionDescriptor
as
Microsoft
.
AspNetCore
.
Mvc
.
Controllers
.
ControllerActionDescriptor
;
string
controllerName
=
action
.
ControllerName
.
ToLower
();
string
actionName
=
action
.
ActionName
.
ToLower
();
if
(!
actionName
.
ToLower
().
Contains
(
"get"
))
{
string
cachedKey
=
SecurityHelper
.
MD5
(
string
.
Format
(
"cmd={0}&token={1}"
,
controllerName
+
"/"
+
actionName
,
token
));
try
var
allowRepeat
=
action
.
MethodInfo
.
GetCustomAttribute
(
typeof
(
AllowRepeatAttribute
));
if
(
allowRepeat
==
null
)
{
if
(
UserReidsCache
.
Exists
(
cachedKey
))
//判断表单是否重复提交
//需进行表单重复提交验证
string
cachedKey
=
SecurityHelper
.
MD5
(
string
.
Format
(
"cmd={0}&token={1}"
,
controllerName
+
"/"
+
actionName
,
token
));
try
{
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
if
(
UserReidsCache
.
Exists
(
cachedKey
))
//判断表单是否重复提交
{
Code
=
(
int
)
ResultCode
.
FormRepeatSubmit
,
Message
=
"表单重复提交,请稍后再试"
,
Data
=
null
});
actionContext
.
Result
=
new
Microsoft
.
AspNetCore
.
Mvc
.
JsonResult
(
new
ApiResult
{
Code
=
(
int
)
ResultCode
.
FormRepeatSubmit
,
Message
=
"表单重复提交,请稍后再试"
,
Data
=
null
});
}
else
{
//默认2秒钟之内不能重复提交
UserReidsCache
.
Set
(
cachedKey
,
1
,
2
);
}
}
else
catch
{
//默认2秒钟之内不能重复提交
UserReidsCache
.
Set
(
cachedKey
,
1
,
2
);
}
}
catch
{
}
}
#
endregion
}
...
...
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