Create a Global Variable
bool IsPageRefresh = false;
Write Below Code on Page Load
#region To Maintain Refresh event //Section of code checks if the page postback is due to genuine submit by user //or by pressing "refresh" or F5 if (!IsPostBack) { Session.Abandon(); Session.Clear(); ViewState["ViewStateId"] = System.Guid.NewGuid().ToString(); Session["SessionId"] = ViewState["ViewStateId"].ToString(); } else { if (ViewState["ViewStateId"] != null && Session["SessionId"] != null) { if (ViewState["ViewStateId"].ToString() != Session["SessionId"].ToString()) { IsPageRefresh = true; } } Session["SessionId"] = System.Guid.NewGuid().ToString(); ViewState["ViewStateId"] = Session["SessionId"].ToString(); } #endregion
Check Global variable where you made the condition like on events
#region To Maintain Refresh event if (IsPageRefresh) { Session.Abandon(); Session.Clear(); } #endregion if (Session["MyFlag"] == null) Response.Redirect("invalid.aspx?msg=Session expired. ", true);
No comments:
Post a Comment