Adding AntiForgeryToken to MVC with jQuery

I’ve seen many posts on how to include MVC’s AntiForgeryToken on a view that is using a javascript framework for its UI. Well, below is a simple solution on how you can implement it. By the way, I am using MVC 3 and jQuery while writing this post.

Include @Html.AntiForgeryToken() on your view. Below is an example view.

On your controller, add the [ValidateAntiForgeryToken] attribute.

To complete the puzzle, lets post our data together with the antiforgery token to our controller action. You need to encode the value of __RequestVerificationToken before posting it, otherwise it will be useless.

And that’s it, as simple as the above.


Author: francorobles

A soon to be jedi in the art of software development...

3 thoughts on “Adding AntiForgeryToken to MVC with jQuery”

  1. hello!,I like your writing so much! share we keep up a correspondence extra about your article on AOL? I require an expert on this space to resolve my problem. May be that is you! Looking ahead to look you. ceffgdabdkdd

  2. Hi, everything is going well here and ofcourse every one is sharing information, that’s really fine, keep up writing. dgdkeeekeedk

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s