Identify Page Refresh in ASP.NET MVC

Identify Page Refresh in ASP.NET MVC

Let say in an online test application with the counter on the top, refreshing the page will start the counter again leading the users to read all the questions again and again.

-One of the solutions to the problem is disable F5 Button using javascript. But there are other options available too for refreshing browser like Right Click select refresh option, click on browser refresh icon. Hence in these cases javascript will not work. So the best option is to use ActionFilter.

– Make an action filter as below:

public class FindRefreshDetectFilter : ActionFilterAttribute,IActionFilter

{

public override void OnActionExecuting(ActionExecutingContext filterContext)

{

var cookie = filterContext.HttpContext.Request.Cookies[“FindRefreshFilter”];

filterContext.RouteData.Values[“IsRefreshed”] = cookie != null &&

cookie.Value == filterContext.HttpContext.Request.Url.ToString();

if ((bool)filterContext.RouteData.Values[“IsRefreshed”])

{

filterContext.Result = new RedirectResult(“~/Online/SignIn”);

}

}

public override void OnActionExecuted(ActionExecutedContext filterContext)

{

filterContext.HttpContext.Response.SetCookie(new HttpCookie(“FindRefreshFilter”,   filterContext.HttpContext.Request.Url.ToString()));

}

}

– Check the value in Controller as :

[FindRefreshDetectFilter]

public ActionResult Test()

{

if ((bool)RouteData.Values[“IsRefreshed”] == true)

return View(“PageRefreshed”);

else

return View();

}

CONCLUSION:

The above Action Filter based solution for detecting page refresh in MVC is not ultimate solution but highly flexible as we can add some more functionality and features according to our need.

Tags:
  • page refresh in asp .net,
  • Page Refresh in ASP.NET MVC,
  • 66 thoughts on “Identify Page Refresh in ASP.NET MVC

    1. Pingback: pornbitter.com
    2. Pingback: pornonaft.net
    3. Pingback: javstreaming.mobi
    4. Pingback: top liwe
    5. Pingback: yotbub
    6. Pingback: yiou
    7. Pingback: hdkino720.info
    8. Pingback: youtotobe.info
    9. Pingback: serial
    10. Pingback: golubaya-laguna
    11. Pingback: articles
    12. Pingback: click to go
    13. Pingback: read
    14. Pingback: Ertugrul 116-117
    15. Pingback: News 26 04 2018
    16. Pingback: socks5
    17. Pingback: click to see more
    18. Pingback: link to the page
    19. Pingback: follow this link
    20. Pingback: go to the source
    21. Pingback: read more
    22. Pingback: here is the link
    23. Pingback: click for details
    24. Pingback: as reported here
    25. Pingback: click to continue
    26. Pingback: read
    27. Pingback: go here
    28. Pingback: notehub.org
    29. Pingback: notehub.org
    30. Pingback: read
    31. Pingback: notehub.org
    32. Pingback: go
    33. Pingback: click to go
    34. Pingback: notehub.org
    35. Pingback: notehub.org
    36. Pingback: notehub.org source
    37. Pingback: click here

    Leave a Reply