title: how can i use AntiForgeryToken with JSON post in mvc 4
body: <p>I have jQuery code that post data with JSON.stringify to controller class but when I used AntiForgeryToken, it doesn't work.. is any better way to secure JSON post or I am missing out something.... </p>
  
  <p>secondly do i need additional to this .. i.e. encryption to secure JSON data...</p>
  
  <p>many thanks for help in advanced...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  $(document).ready(function () {
      $('#id_login_submit').click(function () {
  
          var _authetication_Data = { _UserName: $('#u1').val(),  _Password: $('#p1').val() }
  
          $.ajax({
              type: "POST",
              url: "/Account/ProcessLoginRequest",
              data: JSON.stringify({ model: _authetication_Data }),
              dataType: "json",
              contentType: "application/json; charset=utf-8",
              success: function (response) {
                  alert(response);
              }
  
  
          });
  
      });
  });
  
   &lt;/script&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
  
      @Html.LabelFor(m =&gt; m._UserName)
      @Html.TextBoxFor(m =&gt; m._UserName, new { id = "u1"})
  
  
      @Html.LabelFor(m =&gt; m._Password)
      @Html.PasswordFor(m =&gt; m._Password, new { id = "p1"})
  
  
      &lt;input type="button" id="id_login_submit" value="Login" /&gt;
  }
  </code></pre>
  
  <p></p>
  
  <pre><code>   [HttpPost]
      [ValidateAntiForgeryToken]
      public JsonResult ProcessLoginRequest(LoginModel model)
      {
          string returnString = null;
  
        if (ModelState.IsValid &amp;&amp; WebSecurity.Login(model._UserName, model._Password, persistCookie: true))
          {
              returnString = "user is authenticated";
          }
  
          else
          { returnString = "Message from loginProcess"; }
  
          return Json(returnString, JsonRequestBehavior.AllowGet);
      }
  </code></pre>