The anti-forgery token could not be decrypted

前端 未结 11 1236
萌比男神i
萌比男神i 2020-11-28 08:34

I have a form:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary()...

and a

11条回答
  •  孤街浪徒
    2020-11-28 08:51

    If you use Kubernetes and have more than one pod for your app this will most likely cause the request validation to fail because the pod that generates the RequestValidationToken is not necessarily the pod that will validate the token when POSTing back to your application. The fix should be to configure your nginx-controller or whatever ingress resource you are using and tell it to load balance so that each client uses one pod for all communication.

    Update: I managed to fix it by adding the following annotations to my ingress:

    https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/

    Name    Description Values
    nginx.ingress.kubernetes.io/affinity    Sets the affinity type  string (in NGINX only cookie is possible
    nginx.ingress.kubernetes.io/session-cookie-name Name of the cookie that will be used    string (default to INGRESSCOOKIE)
    nginx.ingress.kubernetes.io/session-cookie-hash Type of hash that will be used in cookie value  sha1/md5/index
    

提交回复
热议问题