Home > Mobile >  ASP redirect with delay
ASP redirect with delay

Time:08-11

if (user.EmailConfirmationCode == confcode) {
  user.EmailConfirmed = true;
  _context.Update(user);
  _context.SaveChanges();
}
else {
  ViewData["Message"] = "Onay kodu hatalı. Kontrol edip tekrar deneyiniz!";
  return Redirect("/onepoint/Login/MailConfirm");
}

I need to go back to MailConfirm with 3 or 4 seconds delay so people can read the message . Above code is in my Controller.cs.

CodePudding user response:

The delay and redirect would probably best be done on the client side.

Example function in Javascript:

function redirectAfterTimeout(){
   setTimeout('Redirect()', 4000);
}
function Redirect() 
{  
    window.location="/onepoint/Login/MailConfirm"; 
}

You could then add a javascript function to the view using a viewbag.

View code:

@if (ViewBag.JavaScriptFunction != null)
    {
        <script type="text/javascript">
            @Html.Raw(ViewBag.JavaScriptFunction)
        </script>
    }

Controller code:

if (user.EmailConfirmationCode == confcode) {
  user.EmailConfirmed = true;
  _context.Update(user);
  _context.SaveChanges();
}
else {
  ViewData["Message"] = "Onay kodu hatalı. Kontrol edip tekrar deneyiniz!";
  ViewBag.JavaScriptFunction = "redirectAfterTimeout();";
}

  • Related