Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Tag Helper: asp-anti-forgery creates error

$
0
0

Hello,

I am building an ASP.NET 5 app on a Mac. I am trying to use the tag helpers feature.  In my controller, I have the following:

[HttpPost("login")]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel viewModel, string returnUrl = null)
{
  if (ModelState.IsValid)
  {

  }
  return View(viewModel);
}

In my view, I have the following:

<form method="POST" action="~/account/login" asp-anti-forgery="true"><h1>Login</h1><div class="validation" asp-validation-summary="All" /><input id="Username" name="Username" /><br /><input id="Password" name="Password" /><br /><button type="submit">Login</button></form>

When I click the Login button, I get the following error:

An unhandled exception occurred while processing the request.

<div class="titleerror">InvalidOperationException: The required anti-forgery form field "__RequestVerificationToken" is not present.</div>

Microsoft.AspNet.Mvc.TokenProvider.ValidateTokens(HttpContext httpContext, ClaimsIdentity identity, AntiForgeryToken sessionToken, AntiForgeryToken fieldToken)

What am I doing wrong?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>