I'm new in asp.net mvc
, i need detect view page refresh with user and do some thing for that purpose read this:
asp.net mvc - Detecting page refresh
for define action filter right click on controller folder and add RefreshDetectFilter
class :
namespace StoreProject.Controllers
{
public class RefreshDetectFilter : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var cookie = filterContext.HttpContext.Request.Cookies["RefreshFilter"];
filterContext.RouteData.Values["IsRefreshed"] = cookie != null &&
cookie.Value == filterContext.HttpContext.Request.Url.ToString();
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
filterContext.HttpContext.Response.SetCookie(new HttpCookie("RefreshFilter", filterContext.HttpContext.Request.Url.ToString()));
}
}
}
and register that in Global.asax
,with this way:
GlobalFilters.Filters.Add(new RefreshDetectFilter());
in my action want to use that action filter with this code:
if (RouteData.Values["IsRefreshed"] == true)
{
// page has been refreshed.
}