简体   繁体   English

将AntiForgeryToken添加到Asp.Net MVC表单

[英]Add AntiForgeryToken to Asp.Net MVC form


I need to add AntiForgeryToken to my application. 我需要将AntiForgeryToken添加到我的应用程序。 I've done following: 我已经完成以下工作:

  1. Add AntiForgeryToken to view: 添加AntiForgeryToken以查看:
 <form id="client-group-details-form" action="" method="post"> <%Html.AntiForgeryToken(); %> //Rest of the form <form> 
  1. Add [ValidateAntiForgeryToken] attribute to specific methods in controller [ValidateAntiForgeryToken]属性添加到控制器中的特定方法

I need to do this also which I'm unable to find out how: 我还需要这样做,但我无法找到方法:

  1. Add _RequestVerificationToken value to the data sent back to server. _RequestVerificationToken值添加到发送回服务器的数据中。 What does it mean and How can I do it? 这是什么意思,我该怎么办?

When you add <%Html.AntiForgeryToken(); %> 当您添加<%Html.AntiForgeryToken(); %> <%Html.AntiForgeryToken(); %> _RequestVerificationToken value will automatically be added to the data that you sent back in the POST request. <%Html.AntiForgeryToken(); %> _RequestVerificationToken值将自动添加到您在POST请求中发送回的数据中。 There is nothing else that needs to be done. 没有什么需要做的。 First check in the POST data, if you see that value or not. 如果没有看到该值,请首先检入POST数据。

To implement antiforgerytoken you need to do two steps 1) Add this line in View 2) Add this line action 要实现防伪令牌,您需要执行两个步骤1)在视图中添加此行2)添加此行操作

Otherthings will be done by asp.net mvc 其他将由asp.net mvc完成

for details: http://innerexception.org/posts/t50-What-is-the-anti-forgery-token-in-asp-net-mvc 有关详细信息: http : //innerexception.org/posts/t50-What-is-the-anti-forgery-token-in-asp-net-mvc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM