Dot.Net Developer

Dot.Net Developer

Share

25/09/2019

In .net core you can add AutoValidateAntiforgeryTokenAttribute in Startup.cs file, So there is no need to add controller or action attribute ([ValidateAntiForgeryToken]) (dependency injection)

So add this to Startup.cs

services.AddMvc(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()))

and then add below to view page .cshtml
AntiForgeryToken()

and in ajax call something like this

$.ajax({
type: "POST",
url: '.Action("actionName", "ControllerName")',
beforeSend: function (request) {
request.setRequestHeader("RequestVerificationToken", $("[name='__RequestVerificationToken']").val());
},
data: data,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) { }.....

Want your business to be the top-listed Computer & Electronics Service in Dublin?
Click here to claim your Sponsored Listing.

Address


Naas Road
Dublin
22