[ValidateAntiForgeryToken] public class LoginModel : PageModel
<el-form style="max-width:600px; margin:20px auto;" method="post"> @Html.AntiForgeryToken()
$.ajaxSetup({ beforeSend: function (xhr) { xhr.setRequestHeader("RequestVerificationToken", $('input:hidden[name="__RequestVerificationToken"]').val()); } })
(有时候这种安全性是没必要须的,好比不是在页面里发起请求,须要采用其它安全机制)html
//在 public void ConfigureServices(IServiceCollection services) 方法里: services.AddMvc() .AddRazorPagesOptions(o => { o.Conventions.ConfigureFilter(new IgnoreAntiforgeryTokenAttribute()); }) .InitializeTagHelper<FormTagHelper>((helper, context) => helper.Antiforgery = false) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);