0

Following the guide from this previous post, I have implemented the only answer from this post in my application. But when I try to actually POST to the action, I get the error "No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.ValidateAntiforgeryTokenAuthorizationFilter' has been registered."

The browser has the token in the cookie, and the Interceptor is appending the token to the request header as "X-XSRF-TOKEN" like I'd expect. The issue is that it no longer hits the API when I add the attribute [ValidateAntiforgeryToken] over one action I'm using to test, but does when I remove it.

I cannot show the code due to privacy reasons, but trust that I have followed the previous example closely. Have I missed something somewhere else? the error makes me think that this only works with razor pages, but my app doesn't use razor pages at all. I am using a SPA design in angular 9 with asp.net core 3.1 API backend

Any advice would be greatly appreciated.

Thanks!

DJBawb
  • 1
  • 1
    Welcome to StackOverflow DJBawb. In case when you cannot provide an example, you can try to reproduce the issue in online code editor or by creating a new small project. It also often helps to understand the problem and find a solution Error says you haven't registered your filter properly – Anatoli Klamer Jul 10 '20 at 01:34
  • thanks for the response. In general, where would I register the filter though? is that something I need to handle in the Configure/ConfigureServices methods in the Startup.cs? My code looks identical to the example I linked, so I felt it was easier than sharing the code by myself. – DJBawb Jul 10 '20 at 14:33
  • Yes, I would start from looking into Startup.cs Sometimes developers use.clear() on service collection before adding their own services – Anatoli Klamer Jul 13 '20 at 06:45

0 Answers0