asp.net mvc 防止重复提交
string hiddenToken = "hiddenToken"; public void OnActionExecuting(ActionExecutingContext filterContext) { string httpMethod = filterContext.RequestContext.HttpContext.Server.HtmlEncode(filterContext.RequestContext.HttpContext.Request.HttpMethod); if (httpMethod == "POST") { // page token // hiddenToken string cacheToken = filterContext.HttpContext.Request[hiddenToken]; //filterContext.HttpContext.Request.IsAjaxRequest() if (cacheToken != null) { if (System.Web.HttpContext.Current.Cache[cacheToken] == null) { System.Web.HttpContext.Current.Cache.Insert(cacheToken, cacheToken, null, DateTime.MaxValue, TimeSpan.FromSeconds(1)); LogHeper.Instant.log.Info("提交成功!"); } else { LogHeper.Instant.log.Info(filterContext.HttpContext.Request.Url + "请不要重复提交!"); throw (new GLRISCRMException("请不要重复提交!")); } } } }
@Html.Hidden("hiddenToken", new Guid().ToString() + DateTime.Now.Ticks)