Whenever an error is thrown in the try-catch block I want to return to the view and display to the user the error. This works fine when I run it on my local machine. However when I push onto the production server I get the error
The required anti-forgery cookie "__RequestVerificationToken" is not present
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
[Authorize(Roles = @"Admin")]
public ActionResult Post(CpjsProcessFormViewModel viewModel)
{
if (ModelState.IsValid)
{
try
{
if (!string.IsNullOrEmpty(viewModel.UserName) && !string.IsNullOrEmpty(viewModel.Password))
{
_sysproCredentials.UserName = viewModel.UserName;
_sysproCredentials.Password = viewModel.Password;
}
var serviceController = new ServiceController(_unitOfWork,
new ControlPlanJobProcessor(_sysproService, _sysproCredentials));
serviceController.ProcessControlPlan(viewModel.ControlPlanId, viewModel.CloseJob, true,
User.Identity.GetUserId());
}
catch (Exception e)
{
ModelState.AddModelError("", e.Message);
return View(viewModel);
}
return RedirectToAction("Post", new { id = viewModel.ControlPlanId, message = "Successfully posted to Syspro" });
}
return View(viewModel);
}
View:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.ControlPlanId)
<div class="form-horizontal">
@Html.ValidationSummary(false, "", new { @class = "text-danger" })
}