Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Razor Page deal with the problem of Ajax Post 400

Shulou Source: shulou.com Published: 2022-06-02 08:37:47 10月01日 Update

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!

Tags: Questions learning security content overall situation security that is ideas situations articles methods is in more sometimes mechanisms frameworks knowledge points articles follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Redmi MySQL macOS