Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At Backend, I have used asp.net web API and I can validate the token by comparing hidden field token and cookies token as shown below:

try
{
  string cookieToken, formToken;
  AntiForgery.GetTokens(null, out cookieToken, out formToken);

  CookieHeaderValue cookie = Request.Headers
                                    .GetCookies(AntiForgeryConfig.CookieName)
                                    .FirstOrDefault();
  if (cookie != null)
  {
    Stream requestBufferedStream = Request.Content.ReadAsStreamAsync().Result;
    requestBufferedStream.Position = 0;
    NameValueCollection myform = Request.Content.ReadAsFormDataAsync().Result;
    try
    {
      AntiForgery.Validate(cookie[AntiForgeryConfig.CookieName].Value,
       myform[AntiForgeryConfig.CookieName]);
    }
    catch (Exception ex)
    {
      throw new HttpResponseException(
       new HttpResponseMessage(HttpStatusCode.Unauthorized));
    }
  }
}


But the main problem is: I am not able to set csrf token using asp.net web API and also the same not able to receive the same csrf token in vue js.

I have a separate project as backend(asp.net web API) and frontend (Vue).




What I have tried:

I only know to validate the token as given above.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900