如何通过AntiForgeryToken在MVC

编程入门 行业动态 更新时间:2024-10-19 10:17:25
本文介绍了如何通过AntiForgeryToken在MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何通过AntiForgeryToken传递到另一个动作?下面就当然不工作:

How to pass through the AntiForgeryToken to another action? The following does of course not work:

[ValidateAntiForgeryToken] public ActionResult CheckSelection(string[] SelectedIds, int SessionId) { ... if (SomeCondition) { return RedirectToAction("Finish", "Session", new { SessionId = SessionId, __RequestVerificationToken = Request.Params["__RequestVerificationToken"] }); } .... }

感谢您的帮助!

推荐答案

这是不可能的。该防伪标记是基于双方的HTTP Cookie和表单中的一个隐藏的价值;做一个动作时重定向,这种形式的价值会丢失,因此防伪标记不能验证。

That is not possible. The anti-forgery token is based on both an Http Cookie and a hidden value in your Form; when doing an Action Redirect, that form value is lost and therefore the anti-forgery token cannot be validated.

您将需要拿出不需要操作重定向设计...

You will need to come up with a design that does not need action redirect...

更多推荐

如何通过AntiForgeryToken在MVC

本文发布于:2023-11-24 21:01:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AntiForgeryToken   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!