Yes there is a built in mechanism. HtmlHelper.AntiForgeryToken, which can be used to help protect your application against cross-site request forgery. To use this feature, call the AntiForgeryToken method from a form and add the ValidateAntiForgeryTokenAttribute attribute to the action method that you want to protect.
CSHTML file:
@Html.AntiForgeryToken()
Controller:
[ValidateAntiForgeryToken]
public ActionResult Edit(User updatedUser)
You'll note that the token involves two safety measures -- a form field and a cookie:
To generate the anti-XSRF tokens, call the @Html.AntiForgeryToken() method from an MVC view or @AntiForgery.GetHtml() from a Razor page. The runtime will then perform the following steps:
If the current HTTP request already contains an anti-XSRF session token (the anti-XSRF cookie __RequestVerificationToken), the security token is extracted from it. If the HTTP request does not contain an anti-XSRF session token or if extraction of the security token fails, a new random anti-XSRF token will be generated.
An anti-XSRF field token is generated using the security token from step (1) above and the identity of the current logged-in user.
If a new anti-XSRF token was generated in step (1), a new session token will be created to contain it and will be added to the outbound HTTP cookies collection. The field token from step (2) will be wrapped in an element, and this HTML markup will be the return value of Html.AntiForgeryToken() or AntiForgery.GetHtml().
Reading: