WHAT IS USE OF [VALIDATEANTIFORGERYTOKEN] IN ASP.NET MVC VIEWS

Sachin Singh

Total Post:26

Points:182
Posted by  Sachin Singh
 997  View(s)
Ratings:
Rate this:
Hi All,

I want to know what is benefit to using [ValidateAntiForgeryToken] in above of our controller view . Here i want to give a snapshot of login partial view:



Please can anyone give me a solution.

Thank you.
  1. Anupam Mishra

    Post:135

    Points:949
    Re: What is use of [ValidateAntiForgeryToken] in ASP.NET MVC Views

    Hi Sachin,

     

    I have generally use  AntiForgeryToken  for prevents external get requests. So no one can access outside.

     Suppose, we are having AntiForgeryToken in our Html.BeginForm in View.

     

    @using (Html.BeginForm())
    {
    @Html.AntiForgeryToken(){}
    }

    When we submit form, we sends data to your Controller method. If method has ValidateAntiForgeryToken attribute, it validates if data we are sending has our  ForgeryToken.ForgeryToken is generated once per session.


     [ValidateAntiForgeryToken]
    public ViewResult Action_Method()
    {
    }


      Modified On Mar-21-2016 12:29:09 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!