How to protect against CSRF by default in ASP.NET MVC 4?

前端 未结 4 385
时光取名叫无心
时光取名叫无心 2021-01-30 14:38

Is there a way to ensure ASP.NET MVC 4 forms are protected against CSRF by default?

For instance, is there a way to have AntiForgeryToken automatically

4条回答
  •  天涯浪人
    2021-01-30 15:21

    I have used FXCop to write two code analysis rules one that require that a HttpMethod attribute is applied to all controller actions and a second that requires any action that has a HttpPost attribute must also have a RequiresAntiForgeryToken attribute.

    This worked well for us. The rules are not particularly hard to write

提交回复
热议问题