[英]Page Redirection on Browser Refresh in Asp.Net
I am developing a Web app for conducting a Online examination. 我正在开发用于进行在线检查的Web应用程序。 I want to stop the contestants from refreshing the page in the browser. 我想阻止参赛者刷新浏览器中的页面。 If they do I want to navigate them to a page which says they are disqualified. 如果他们愿意,我想将他们导航到一个页面,该页面显示他们不合格。 How can I implement this? 我该如何实施?
The following code snippet detects 'Refresh' in page_load function 以下代码段在page_load函数中检测到“刷新”
bool IsPageRefresh = false;
protected void Page_Load(object sender, EventArgs e)
{
//this section of code checks if the page postback is due to genuine submit by user or by pressing "refresh"
if (!IsPostBack)
{
ViewState["ViewStateId"] = System.Guid.NewGuid().ToString();
Session["SessionId"] = ViewState["ViewStateId"].ToString();
}
else
{
if (ViewState["ViewStateId"].ToString() != Session["SessionId"].ToString())
{
IsPageRefresh = true;
}
Session["SessionId"] = System.Guid.NewGuid().ToString();
ViewState["ViewStateId"] = Session["SessionId"].ToString();
}
}
You can then use the 'IsPageRefresh' boolean flag in the code-behind to determine if it's a postback due to genuine User submit action or by browser 'Refresh'. 然后,您可以在后面的代码中使用'IsPageRefresh'布尔标志来确定它是由于真正的用户提交操作还是通过浏览器'Refresh'而回发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.