Base solution for your next web application
Open Closed

CSRF Token on aspnet zero angular #11535


User avatar
0
amasanad created

how to implemetn CSRF token on aspnet zero with angualr front end on all pages post login


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @amasanad

    If you want to do this, you host your Angular app under your Web.Host app or you can create a new ASP.NET Core app and host your Angular app under that one.

  • User Avatar
    0
    amasanad created

    Hello i followed this tutrial and token is now sent on header from angualr to backend https://www.c-sharpcorner.com/article/preventing-csrf-attacks-using-asp-net-core-javascript-and-angular/ the issue now i'm gettgin exception

    INFO 2023-04-03 13:02:15,539 [13 ] idateAntiforgeryTokenAuthorizationFilter - Antiforgery token validation failed. The required antiforgery cookie "XSRF-TOKEN" is not present. Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The required antiforgery cookie "XSRF-TOKEN" is not present. at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.ValidateRequestAsync(HttpContext httpContext) at Microsoft.AspNetCore.Mvc.ViewFeatures.Filters.ValidateAntiforgeryTokenAuthorizationFilter.OnAuthorizationAsync(AuthorizationFilterContext context)

    please help, if you can include refrence for soltuion

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    As you can see, you need to send XSRF-TOKEN using cookies as the error message states;

    The required antiforgery cookie "XSRF-TOKEN" is not present.