Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:38:51+00:00 2026-06-11T16:38:51+00:00

I have been successfully using the AntiForgery option with Ajax in Orchard Modules for

  • 0

I have been successfully using the AntiForgery option with Ajax in Orchard Modules for a while. Recently, I have been wanting to change from using the default ContentType = ‘application/x-www-form-urlencoded; charset=UTF-8′ to a JSON payload (ContentType=’application/JSON’).

As soon as I do this I get an exception thrown by ASP.NET ‘A required anti-forgery token was not supplied or was invalid.’. OK, but how do I go about adding the __RequestVerificationToken while preserving JSON payload?

For reference, here is the code I’m using:

    var config = {
        url: url,
        type: "POST",
        data: data ,
        dataType: "json",
        contentType: "application/json; charset=utf-8"
    };
    $.ajax(config);

Controller (blows up with ‘A required anti-forgery token was not supplied or was invalid.’ before it gets here):

    [HttpPost]
    public ActionResult Update(ShoppingCartItemVM[] items)
    {
       // do stuff
    }

Is this a limitation of the Orchard AntiForgery wrapper or of the MVC AntiForgery functionality? Or am I being stupid (again)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:38:52+00:00Added an answer on June 11, 2026 at 4:38 pm

    Giscard is correct. I’ll dig a bit deeper.

    Note: Only the “post” results in orchard controller require the anti forgery token. So there is less of a requirement to remember that where using a “Get” in a request for json.

    Often you will want to send more data than just the request token. In that case the ‘data’ object you send with your request must contain that __RequestVerificationToken value. In that case jQuery is useful for example:

    var defaultPostValues = { __RequestVerificationToken:'@Html.AntiForgeryTokenValueOrchard()', id: 1, ..etc.. };
    var myValues = { answers: [1,5,5,10] };
    var data = $.extend({}, defaultPostValues, myValues); 
    
    var config = {
        url: url,
        type: "POST",
        data: data ,
        dataType: "json",
        contentType: "application/json; charset=utf-8"
    };
    $.ajax(config);
    

    The anti-forgery token can also be turned off per module definition (if I remember correctly?).
    Module.txt

    Name: Polls
    AntiForgery: false
    Author: Matt
    ... removed for brevity 
    Features:
        Polls
    ... etc
    

    However I would recommend using the antiforgery if your calls are within Orchard’s modules, and disabling if and only if your data is needed else where by external requests. But I would recommend WebAPI within Orchard for that case but that creates a whole new story and probably likely moves far out of scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a few months I have been successfully using David Justices Default Button example
I have been able to successfully get an access token from Vimeo using the
All these years i have been successfully using EnumServicesStatus in combination with OpenScManager (with
I have a Linq-To-Sql based repository class which I have been successfully using. I
I have successfully been using the eclipse Indigo internal browser to view my web
I have successfully been using Win32::Ole module to browser through pages and submit forms.
I have been using fullcalendar plugin successfully for a few months and suddenly ran
I have been trying to post using RestKit after I have successfully used it
I have started using https://github.com/omab/django-social-auth and been successfully able to login via twitter, google
I have been successfully using my code with the javascript library in the ANTLR

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.