Product Bundles
DevCraft
All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:
Web
Mobile
Document Management
Desktop
Reporting
Testing & Mocking
CMS
UI/UX Tools
Debugging
Free Tools
Support and Learning
Productivity and Design Tools
Hi Lenny,Thank you for the details provided.
In order to achieve the described behavior, I would recommend to configure the anti-forgery settings as follows:
In your Startup.cs or Program.cs:
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddAntiforgery(options => { options.HeaderName = "X-CSRF-TOKEN"; }); }
var token = $('input[name="__RequestVerificationToken"]').val(); e.XMLHttpRequest.setRequestHeader("X-CSRF-TOKEN", token);
@Html.AntiForgeryToken()
[HttpPost] [ValidateAntiForgeryToken] public IActionResult Upload(IFormFile file) { }
Kind Regards,
Anton Mironov
Thanks. I figured it out. I added this bit of script to the Upload client side event handler.
Hi Lenny,Thank you for sharing the code with the community.
Best Regards,Anton Mironov
Hi Lenny,
Thank you for the details provided.
In order to achieve the described behavior, I would recommend to configure the anti-forgery settings as follows:
In your Startup.cs or Program.cs:
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddAntiforgery(options => { options.HeaderName = "X-CSRF-TOKEN"; }); }
var token = $('input[name="__RequestVerificationToken"]').val(); e.XMLHttpRequest.setRequestHeader("X-CSRF-TOKEN", token);
Ensure the anti-forgery token is available in the View:
[HttpPost] [ValidateAntiForgeryToken] public IActionResult Upload(IFormFile file) { }
Kind Regards,
Anton Mironov
Thanks. I figured it out. I added this bit of script to the Upload client side event handler.
if(xhr) {
xhr.addEventListener("readystatechange", function (e) {
if (xhr.readyState == 1 ) {
xhr.setRequestHeader('RequestVerificationToken', getAntiForgeryToken());
}
});
}
Hi Lenny,
Thank you for sharing the code with the community.
Best Regards,
Anton Mironov