Why does @Html.AntiForgeryToken() generate different tokens in same response?

后端 未结 6 701
一向
一向 2020-12-16 04:32

A single Razor view contains several forms, each with its own call to @Html.AntiForgeryToken()

@Html.AntiForgeryToken
6条回答
  •  庸人自扰
    2020-12-16 04:53

    @Html.AntiForgeryToken() basically generate encrypted value based on the cookie and form data. So if you declare and use this @Html.AntiForgeryToken() for each than it will generate two different _RequestValidationToken. Better declare one global @token variable with @Html.AntiForgeryToken() method and it will create a single token for each request.

提交回复
热议问题