MVC 5 Preventing Cross-Site Request Forgery(CSRF) Attacks Table of Contents 1. In the 1st step add the function GetTokenHeader() to get token header. 2. In second step add the script code for post the ajax request with token header for API controller. 3. Add the ValidateAntiForgeryToken attribute for validate the antiforgery token on controller actions. 4. validate the all request using RequestVerificationToken and HttpRequestMessage. The below video show the steps where put the codes For more details seen the below example. //Step 1 //Put the code in cshtml page @{ Models.UserSession userSession = (Models.UserSession)Session["userSession"]; @functions{ public string GetTokenHeader() { string cookieToken, formToken; AntiForgery.GetTokens(null, out cookieToken, out formToken); return cookieToken + ":" + formToken; } } } //Step 2 //Th...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers