0

I want to login with bootbox.dialog. I post a HTML.Form in the following syntax:

 $.get("/account/ajaxlogin", function (data2) {
 bootbox.dialog({
      title: '<h4 style="color:white;">Login</h4>',
      message: data2,
      buttons: {
      "success": {
      "label": "Login",
      "className": "btn-large btn-success",
      "callback": function (e) {
       var flag = false;
        $.ajax({
          url: "/account/login",
          data:$("form").serialize(),
          type: "POST",
          success: function (responseData) {}});

When i click in Login button, i get AntiForgeryToken exception

The anti-forgery token could not be decrypted. If this application is hosted by a Web Farm or cluster, ensure that all machines are running the same version of ASP.NET Web Pages and that the &lt;machineKey&gt; configuration specifies explicit encryption and validation keys. AutoGenerate cannot be used in a cluster.

I add a manual machine key definition in your web.config

<machineKey validationKey="40146620D52D81D5F0880209AC6F0C62D80686A5D1CC01E3AB1F75FA92B8DC775B0F97745973D9B69373111D6E7C5F4417B1212D7DD947BAE2AC4E2B10E8DECA" decryptionKey="D3231059079250E64E490418C8860435326DBD9946ABED2D9832E66D20F027AF" validation="SHA1" decryption="AES" />

I use the http://aspnetresources.com/tools/keycreator.aspx

Niloo
  • 1,205
  • 5
  • 29
  • 53
  • Check this thread: http://stackoverflow.com/questions/14473597/include-antiforgerytoken-in-ajax-post-asp-net-mvc – ntl Aug 28 '14 at 07:59
  • Tnaks, i use this link, but i get error again. I have `__RequestVerificationToken` in data. – Niloo Aug 28 '14 at 08:11

1 Answers1

0

Few days back i encountered with the same problem , I solved it because there were multiple @Html.AntiForgeryToken() pieces of code on my page. I had 2 on my page and once I removed the second one, this error went away.

OR Try sending AntiForgeryToken with data in ajax call.

data : { __RequestVerificationToken: $('input[name="__RequestVerificationToken"]').val() }
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
  • Thanks, but i have one. – Niloo Aug 28 '14 at 08:03
  • I use `AddAntiForgeryToken = function (data) { data.__RequestVerificationToken =$('input[name=__RequestVerificationToken]').val(); return data; };` for data but i get error again :( – Niloo Aug 28 '14 at 08:17
  • I remove `@Html.AntiForgeryToken()` from partial, i don't get error but send null value for post action. i have data `"__RequestVerificationToken=JSSX1QVs6z0Lr0409v4lebj_00w5UonDNaMxSQzM3L5_YmSi4XQ_5R5Y7f9sJ6KPBl28zvqCc9j0RSZIazMIvXbY4wQvddQGrg80zp_KBal922EUUUZCkep07gpl7ZvuxSVRKQ2&UserName=&Password=&UserName=arg&Password=123456"` – Niloo Aug 28 '14 at 08:24
  • @Niloo..strange...just try removing antiforgery from both controller and page – Kartikeya Khosla Aug 28 '14 at 08:40