How does Razor Page deal with the problem of Ajax Post 400
This article mainly explains "how Razor Page deals with Ajax Post 400s". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how Razor Page deals with Ajax Post 400s".
In order to prevent CSRF attacks, the new version of the framework has enhanced the relevant processing by adding [ValidateAntiForgeryToken] [ValidateAntiForgeryToken] public class LoginModel: PageModelHtml to generate token @ Html.AntiForgeryToken () global settings Ajax to submit token $.ajaxSetup ({beforeSend: function (xhr) {xhr.setRequestHeader ("RequestVerificationToken", $('input: hidden [name = "_ RequestVerificationToken"]'). Val ()) }}) disable the above settings
(sometimes this security is not necessary, for example, if you do not initiate a request on the page, you need to use other security mechanisms.)
/ in the public void ConfigureServices (IServiceCollection services) method: services.AddMvc () .AddRazorPagesOptions (o = > {o.Conventions.ConfigureFilter (new IgnoreAntiforgeryTokenAttribute ());}) .InitializeTagHelper ((helper, context) = > helper.Antiforgery = false) .SetCompatibilityVersion (CompatibilityVersion.Version_2_2)
Reference: https://www.cnblogs.com/tdfblog/p/disable-antiforgery-token-validation-in-asp-net-core-razor-page.html
Thank you for your reading, the above is the content of "how Razor Page deals with the problem of Ajax Post 400". After the study of this article, I believe you have a deeper understanding of how Razor Page deals with the problem of Ajax Post 400. the specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!