Click here to Skip to main content
14,920,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to generate an anti-forgery token and it is checked every pages and every action to check and validate token but not regenerate token. the token is every time constant.

What I have tried:

i tried in every .cshtml page
put @Html.AntiForgeryToken()

in .cshtml page below code
               @using (Html.BeginForm("ViewSearchAcknowledgementCase", "Manan", FormMethod.Post, new { @id = "Family", role = "form" }))

                   <table id="ContentPlaceHolder1_tbldetail" cellspacing="15" width="97%">
                       <tr align="right">
                           <td colspan="4">
                               <span id="ContentPlaceHolder1_lblmandatory" style="color:Red;">*  Mandatory Field!</span>


and every action method i checked

and action method like below

       public ActionResult ViewAcknowledgement()
           M_Login ml = new M_Login();
Updated 6-Aug-18 2:08am
Richard Deeming 3-Aug-18 10:42am
A constant anti-forgery token would not provide any protection at all.

Perhaps if you update your question to explain the problem you're actually trying to solve, rather that asking for help with your chosen solution for that problem, somebody might be able to point you in the right direction.
Member 13140552 4-Aug-18 2:45am
Thanks Richard,

I some code put in tried example, how i use that? to changing every page redirect and action to change token...?

1 solution

The anti-forgery token needs to be inside the form.
@using (Html.BeginForm(...)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900