Commit 0dcb5b00 authored by 黄奎's avatar 黄奎

Merge branch 'master' of http://gitlab.oytour.com/Kui2/education

parents f8e00fe7 9e3dd12d

using System;
namespace Edu.WebApi.Filter
{
/// <summary>
/// 允许重复提交表单属性
/// </summary>
public class AllowRepeatAttribute : Attribute
{
}
}
\ No newline at end of file
......@@ -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
}
......
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