0
我使用這個代碼,以確定我的頁面刷新,但它總是回來在我的控制器是真正刷新檢測過濾器始終是真實的
public class RefreshDetectFilter : ActionFilterAttribute, IActionFilter
{
//void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var cookie = filterContext.HttpContext.Request.Cookies["RefreshFilter"];
filterContext.RouteData.Values["IsRefreshed"] = cookie != null &&
cookie.Value == filterContext.HttpContext.Request.Url.ToString();
}
//void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
filterContext.HttpContext.Response.SetCookie(new HttpCookie("RefreshFilter", filterContext.HttpContext.Request.Url.ToString()));
}
}
我有屬性和檢查
[RefreshDetectFilter]
public class UserController : Controller
的操作方法
if (Convert.ToBoolean(RouteData.Values["IsRefreshed"]) == true)
{
// page has been refreshed.
}