I have got one GET ActionResult and one POST ActionResult. After a POST, a customized link appears for the user to click to get redirected to another page.
Thereafter, when the user presses the back button in their browser, the form gets resubmitted and a new customized link appears again. This is undesired. I would much rather the form completely clears out and be empty than this happening. Alternatevily, only go back to the same state before the redirection (same link showing and no resubmission happening)
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ShortenURL(ShortURLModel model)
{
if (ModelState.IsValid)
{
ViewBag.currentdomain = GetCurrentAbsoluteURL();
Tuple<bool, string> response = _shortUrlProcessor.CreateShortURL(model.originalURL, model.shortURL);
if (response.Item1)
{
ViewBag.ShortenURLSuccess = true;
ViewBag.shortlink = ViewBag.currentdomain + response.Item2;
}
else
{
ViewBag.ShortenURLSuccess = false;
}
}
return View();
}
[HttpGet]
[Route("{*id}")]
public IActionResult ShortenURL(string id)
{
ViewBag.currentdomain = GetCurrentAbsoluteURL();
if (id == null)
{
return View();
}
var originalURL = _shortUrlProcessor.GetOriginalURL(id);
if (originalURL == null)
{
return Redirect("~/");
}
return Redirect(originalURL);
}