Global ValidateAntiForgeryToken in MVC3

Posted by Nettuce on Geeks with Blogs See other posts from Geeks with Blogs or by Nettuce
Published on Sun, 30 Jan 2011 21:24:33 GMT Indexed on 2011/01/30 23:26 UTC
Read the original article Hit count: 164

Filed under:
public class GlobalValidateAntiForgeryToken : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.HttpContext.Request.HttpMethod == WebRequestMethods.Http.Post)
            {
               new ValidateAntiForgeryTokenAttribute().OnAuthorization(filterContext);
            }
        }
    }

And add to the Global.asax:

       public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new GlobalValidateAntiForgeryToken());
        }

© Geeks with Blogs or respective owner