Open Closed

navigator.sendBeacon does not work with API endpoint #6648


User avatar
0
trina.thompson created
  • ABP Framework version: v7.2.2
  • UI Type: MVC
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

I am trying to call one of our API endpoints using navigator.sendBeacon and it always throws a 400 error. This same end point works if I do it as an AJAX call instead. Can you please advise what may be needed to configure this to work properly?


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You may not be passing the CSRF token parameter

    ABP will set it internally for Ajax https://github.com/abpframework/abp/blob/e57159f1b96a4937d75793874f9ed89d1c2131c4/npm/packs/jquery/src/abp.jquery.js#L255

  • User Avatar
    0
    trina.thompson created

    Hello,

    Thank you for your suggestion. I tried adding this to the API Endpoint [IgnoreAntiforgeryToken]. I also tried passing the token in the header in your example. Both still resulted in a 400 error.

    Do you have any other suggestions?

  • User Avatar
    0
    trina.thompson created

    I was able to solve this by disabling AbpAutoValidateAntiforgeryTokenAuthorizationFilter for the controller that we need to call with navigator.sendBeacon. We set a custom AbpAntiForgeryOptions.AutoValidateFilter for this purpose.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09