You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using System.Net;
- using System.Web.Helpers;
- using System.Web.Mvc;
-
- namespace Learun.Application.Web
- {
- /// <summary>
- /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
- /// Copyright (c) 2013-2018 北京泉江科技有限公司
- /// 创建人:陈彬彬
- /// 日 期:2017.03.08
- /// 描 述:防伪验证
- /// </summary>
- public class HandlerValidateAntiForgeryTokenAttribute:AuthorizeAttribute
- {
- /// <summary>
- /// 拦截器
- /// </summary>
- /// <param name="filterContext">http上下文</param>
- public override void OnAuthorization(AuthorizationContext filterContext)
- {
- var request = filterContext.HttpContext.Request;
- if (request.HttpMethod == WebRequestMethods.Http.Post)
- {
- if (request.IsAjaxRequest())
- {
- var antiForgeryCookie = request.Cookies[AntiForgeryConfig.CookieName];
- var cookieValue = antiForgeryCookie != null
- ? antiForgeryCookie.Value
- : null;
- //从cookies 和 Headers 中 验证防伪标记
- //这里可以加try-catch
- AntiForgery.Validate(cookieValue, request.Headers["__RequestVerificationToken"]);
- }
- else
- {
- new ValidateAntiForgeryTokenAttribute().OnAuthorization(filterContext);
- }
- }
- }
- }
- }
|