Geeks With Blogs
.Nettuce Code Salad
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());
        }
Posted on Sunday, January 30, 2011 9:24 PM | Back to top


Comments on this post: Global ValidateAntiForgeryToken in MVC3

# re: Global ValidateAntiForgeryToken in MVC3
Requesting Gravatar...
Thank you, its ease to use and will do it globally
Left by Umesh Maharjan on Sep 11, 2011 3:45 AM

# re: Global ValidateAntiForgeryToken in MVC3
Requesting Gravatar...
but fren it doesn't work on Ajax or Jquery
always catch invalid,

any suggestion from you
Left by umesh maharjan on Sep 11, 2011 4:00 AM

Your comment:
 (will show your gravatar)


Copyright © Jon Canning | Powered by: GeeksWithBlogs.net