asp.net MVC antiforgerytoken on exception RedirectToAction

后端 未结 2 1810
梦如初夏
梦如初夏 2021-02-08 05:11

I have implimented the AnitforgeryToken with my asp.net MVC forms, and also added the attribute to my login procedure, however when the check failes i wish to redirect to my fra

2条回答
  •  名媛妹妹
    2021-02-08 05:46

    The ValidateAntiForgeryTokenAttribute will just throw HttpAntiForgeryException. You could use the HandleErrorAttribute to handle this scenario:

    [HandleError(
        ExceptionType = typeof(HttpAntiForgeryException), 
        View = "Unauthorized")]
    [ValidateAntiForgeryToken]
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SomeActionThatRequiresToken() 
    {
        return View();
    }
    

提交回复
热议问题