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()

example
in .cshtml page below code
@Html.AntiForgeryToken();
               @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>
                           </td>
                       </tr>


-------------------------------------------

and every action method i checked
[ValidateAntiForgeryToken]

and action method like below

[ValidateAntiForgeryToken]
     [HttpPost]
       public ActionResult ViewAcknowledgement()
       {
           M_Login ml = new M_Login();
           try
           {
Posted
Updated 6-Aug-18 2:08am
v2
Comments
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(...)
{
    @Html.AntiForgeryToken();
   

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