problem in clearing the sessions
-
hello all, I have made a project like OnlineExam. In this, I want to restrict the Back button of the client browser so that after submitting the test, it should redirect last page or you can say results page. And if user clicks on the back button, it should not redirect to the Questions page again, plz help Thanks in advance.
-
hello all, I have made a project like OnlineExam. In this, I want to restrict the Back button of the client browser so that after submitting the test, it should redirect last page or you can say results page. And if user clicks on the back button, it should not redirect to the Questions page again, plz help Thanks in advance.
Although, there are lots of hacks using javascript to disallow navigating back, but those are, as per my belief, not all foolproof. I would suggest you to use Cache.SetNoStore() on the page where you don't want to allow user to visit using back button. Back button actually presents the page using stored cache on browser client. Here is the code which you can place in page load event...
Response.Cache.SetNoStore();
This will make each and every visit to this page to be fetched from server. You can add some code logic or session variable etc to check if it is a valid page request. I hope this will help.
puranonnet@hotmail.com BCS Technology
-
Although, there are lots of hacks using javascript to disallow navigating back, but those are, as per my belief, not all foolproof. I would suggest you to use Cache.SetNoStore() on the page where you don't want to allow user to visit using back button. Back button actually presents the page using stored cache on browser client. Here is the code which you can place in page load event...
Response.Cache.SetNoStore();
This will make each and every visit to this page to be fetched from server. You can add some code logic or session variable etc to check if it is a valid page request. I hope this will help.
puranonnet@hotmail.com BCS Technology
no friend..its not working ....i have already used it......
-
hello all, I have made a project like OnlineExam. In this, I want to restrict the Back button of the client browser so that after submitting the test, it should redirect last page or you can say results page. And if user clicks on the back button, it should not redirect to the Questions page again, plz help Thanks in advance.
You need two session variables. ExamStarted and ExamFinished. Set the ExamStarted variable when they start the exam. When they submit the test set the ExamFinished variable. Then in every question page check for the ExamFinished session variable. If it is set then redirect.
-
hello all, I have made a project like OnlineExam. In this, I want to restrict the Back button of the client browser so that after submitting the test, it should redirect last page or you can say results page. And if user clicks on the back button, it should not redirect to the Questions page again, plz help Thanks in advance.
You can disable the Browser back button such that the scenario does not occur:
// Code disables caching by browser. Hence the back browser button
// grayed out and could not causes the Page_Load event to fire
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();You can add something similar in form aspx if you want to place it there:
OR
//clears browser history and redirects url
<SCRIPT LANGUAGE=javascript> { var Backlen=history.length; history.go(-Backlen); window.location.href=page url }</SCRIPT>OR
Page.ClientScript.RegisterStartupScript(this.GetType(),"cle","windows.history.clear",true);
OR as you say in you logout event:
protected void LogOut()
{
Session.Abandon();
string nextpage = "Logoutt.aspx";
Response.Write("<script language=javascript>");
Response.Write("{");
Response.Write(" var Backlen=history.length;");
Response.Write(" history.go(-Backlen);");
Response.Write(" window.location.href='" + nextpage + "'; ");
Response.Write("}");
Response.Write("</script>");
} -
hello all, I have made a project like OnlineExam. In this, I want to restrict the Back button of the client browser so that after submitting the test, it should redirect last page or you can say results page. And if user clicks on the back button, it should not redirect to the Questions page again, plz help Thanks in advance.
I would approach it differently. I would create multiple ascx files if you want different "pages" and step through these .ascx files by postback. This makes the system far more extensible because if you want to add new questions, or add questions dynamically, all you have to do create another .ascx file and reference it in the .aspx page. Or, you could reate one .ascx file and load the questions dynamically from a database or XML file, and just use postback to keep track of each question. Keep track of the current question with a session state, but then the "back" and "forward" buttons become irrelevant because you are displaying whatever .ascx file you've selected in postback. Ryan
-
I would approach it differently. I would create multiple ascx files if you want different "pages" and step through these .ascx files by postback. This makes the system far more extensible because if you want to add new questions, or add questions dynamically, all you have to do create another .ascx file and reference it in the .aspx page. Or, you could reate one .ascx file and load the questions dynamically from a database or XML file, and just use postback to keep track of each question. Keep track of the current question with a session state, but then the "back" and "forward" buttons become irrelevant because you are displaying whatever .ascx file you've selected in postback. Ryan
I have used simple web page for the questions to be displayed. After submitting the questions, user redirects to another page i.e. thanks.aspx and in that page, I have used the session.removeAll() in the PageLoad event. Now I want that when user clicks on the back button of his browser from that page(i.e thanks.aspx), Questions.aspx page should not display the same questions again. Instead, that page must be empty. I hope u get my point.. thanks anyways
-
I have used simple web page for the questions to be displayed. After submitting the questions, user redirects to another page i.e. thanks.aspx and in that page, I have used the session.removeAll() in the PageLoad event. Now I want that when user clicks on the back button of his browser from that page(i.e thanks.aspx), Questions.aspx page should not display the same questions again. Instead, that page must be empty. I hope u get my point.. thanks anyways
That's even easier to fix. From what I understand you basically have two pages: test.aspx and thankyou.aspx . Test.aspx as all of your questions and thank has all of your processing code. Test.aspx redirects to thankyou.aspx . If this is the case, here is what I would do: On any page before you go to test.aspx (I'm sure you have a page like (testinstructions.aspx), create a session:
Session[TEST_FINISHED] = false;
Then check the test page for the session:bool bTestComplete = (bool)Session[TEST_FINISHED];
//If this is true, the user probably hit the back button, get him back to the thank you page.
if (bTestComplete == true)
{
Response.Redirect(thankyou.aspx);
}Finally, set a session on thankyou.aspx like this:
Session[TEST_FINISHED] = true;
So when the user lands on the test page, the TEST_FINISHED session is set to true. This will insure that the user is never able to go back to the test page. Is that what you are looking for? Ryan McBeth -
That's even easier to fix. From what I understand you basically have two pages: test.aspx and thankyou.aspx . Test.aspx as all of your questions and thank has all of your processing code. Test.aspx redirects to thankyou.aspx . If this is the case, here is what I would do: On any page before you go to test.aspx (I'm sure you have a page like (testinstructions.aspx), create a session:
Session[TEST_FINISHED] = false;
Then check the test page for the session:bool bTestComplete = (bool)Session[TEST_FINISHED];
//If this is true, the user probably hit the back button, get him back to the thank you page.
if (bTestComplete == true)
{
Response.Redirect(thankyou.aspx);
}Finally, set a session on thankyou.aspx like this:
Session[TEST_FINISHED] = true;
So when the user lands on the test page, the TEST_FINISHED session is set to true. This will insure that the user is never able to go back to the test page. Is that what you are looking for? Ryan McBethyes ....I wanted to have like that and I have used that code in my project but every time, after clicking on the submit button of the test.aspx page & it redirects to the thanks.aspx, When user clicks on the back button,again it redirects to the test.aspx webpage and in that page,questions are displayed in the same way...... could you give me alternative of using sessions in my project ??? And thanks for the answer
-
yes ....I wanted to have like that and I have used that code in my project but every time, after clicking on the submit button of the test.aspx page & it redirects to the thanks.aspx, When user clicks on the back button,again it redirects to the test.aspx webpage and in that page,questions are displayed in the same way...... could you give me alternative of using sessions in my project ??? And thanks for the answer
It may be tough to do unless you use session states because you have to record the state of the user. If you put the
Response.redirect("thanks.aspx")
in the page_load method along with the if Statement, it should work by kicking the user out. But there is always another way. Let me think about it. Ryan McBeth -
yes ....I wanted to have like that and I have used that code in my project but every time, after clicking on the submit button of the test.aspx page & it redirects to the thanks.aspx, When user clicks on the back button,again it redirects to the test.aspx webpage and in that page,questions are displayed in the same way...... could you give me alternative of using sessions in my project ??? And thanks for the answer
Ok, brother I'm still on the case. I can think of one more option if sessions are out of the question. Create a third page called process.aspx . process.aspx -> thankyou.aspx If the user hits the back button, they go immediately to process.aspx and get redirected back to thankyou.aspx . Now, this won't help if the user holds down the "back" key and chooses test.aspx, but it may work in 90% of your cases, and if you are having trouble with setting sessions, that may be good enough. If that won't work, post your page_load method for test.aspx and thankyou.aspx and I'll take a look at it. Ryan
-
Ok, brother I'm still on the case. I can think of one more option if sessions are out of the question. Create a third page called process.aspx . process.aspx -> thankyou.aspx If the user hits the back button, they go immediately to process.aspx and get redirected back to thankyou.aspx . Now, this won't help if the user holds down the "back" key and chooses test.aspx, but it may work in 90% of your cases, and if you are having trouble with setting sessions, that may be good enough. If that won't work, post your page_load method for test.aspx and thankyou.aspx and I'll take a look at it. Ryan
alright...I'll try this..will get back to you. thanks
-
alright...I'll try this..will get back to you. thanks
hi Ryan.. I have implemented the idea of including the third page(say process.aspx) between the test.aspx and thanks.aspx.But,the Third page inclusion does help somewhat but what if user clicks browser's back button subsequently after submitting the test....? By doing this, user redirects to the first page again, and between these subsequent clicks, the pages showing the same data again and again..
-
hi Ryan.. I have implemented the idea of including the third page(say process.aspx) between the test.aspx and thanks.aspx.But,the Third page inclusion does help somewhat but what if user clicks browser's back button subsequently after submitting the test....? By doing this, user redirects to the first page again, and between these subsequent clicks, the pages showing the same data again and again..
Okay, Maybe I'm not understanding the whole scope of the problem. If you set a session on the test page and check for that session in the page_load and force a redirect if the test has been submitted, any subsequent return to that page should force the user back to the "thankyou.aspx" page. This is especially frustrating because I work for a company that writes online personality tests. So here's what I do in a nutshell with very, very simplified business logic: notification.aspx -> answerSheet.aspx -> thankyou.aspx What I really do is keep it all on the same page and use AJAX and custom controls, but that doesn't help you with your problem. So here is the rundown (forgive me if there are syntax mistakes here, I'm doing this quick before a meeting): notification.aspx - This page explains the test, sets up some user info and sets the following in page_load.
protected void Page\_Load(object sender, System.EventArgs e) { Session\[COMPLETE\] = false; //The rest of the page loading code down here }
answerSheet.aspx - This page has the radio buttons for answers. It's here that I would have the following code inside the Page_Load() method in the answersheet.aspx codebehind file:
protected void Page\_Load(object sender, System.EventArgs e) { if (Session\[COMPLETE\] == null) { //Then we are in a state that we shouldn't be in, push back to the notification page. Response.Redirect("notification.aspx"); } if (Session\[COMPLETE\] == true) { //Then the user has already taken the test, push forward to "thank\_you" Response.Redirect("answerSheet.aspx"); } ///The rest of the page code down here }
thankyou.aspx - This page would have the following code:
protected void Page\_Load(object sender, System.EventArgs e) { Session\[COMPLETE\] == true; //The rest of the page loading code down here }
The following code will allow the user to go back to the answer sheet, but it won't matter because on page load, they will be redirected back to the thank you page. I will not give up on you, brother. If this doesn't help, post the code in the page_load methods and we can go from there. Ryan McBeth
-
Okay, Maybe I'm not understanding the whole scope of the problem. If you set a session on the test page and check for that session in the page_load and force a redirect if the test has been submitted, any subsequent return to that page should force the user back to the "thankyou.aspx" page. This is especially frustrating because I work for a company that writes online personality tests. So here's what I do in a nutshell with very, very simplified business logic: notification.aspx -> answerSheet.aspx -> thankyou.aspx What I really do is keep it all on the same page and use AJAX and custom controls, but that doesn't help you with your problem. So here is the rundown (forgive me if there are syntax mistakes here, I'm doing this quick before a meeting): notification.aspx - This page explains the test, sets up some user info and sets the following in page_load.
protected void Page\_Load(object sender, System.EventArgs e) { Session\[COMPLETE\] = false; //The rest of the page loading code down here }
answerSheet.aspx - This page has the radio buttons for answers. It's here that I would have the following code inside the Page_Load() method in the answersheet.aspx codebehind file:
protected void Page\_Load(object sender, System.EventArgs e) { if (Session\[COMPLETE\] == null) { //Then we are in a state that we shouldn't be in, push back to the notification page. Response.Redirect("notification.aspx"); } if (Session\[COMPLETE\] == true) { //Then the user has already taken the test, push forward to "thank\_you" Response.Redirect("answerSheet.aspx"); } ///The rest of the page code down here }
thankyou.aspx - This page would have the following code:
protected void Page\_Load(object sender, System.EventArgs e) { Session\[COMPLETE\] == true; //The rest of the page loading code down here }
The following code will allow the user to go back to the answer sheet, but it won't matter because on page load, they will be redirected back to the thank you page. I will not give up on you, brother. If this doesn't help, post the code in the page_load methods and we can go from there. Ryan McBeth
thanks for your concern Ryan. But i have implemented another alternative for this. I have used onLoad event in the thanks.aspx in its body section as following: ....................... ............. by doing this,the back button after reaching at thanks.aspx webpage, is disabled. It means it doesn't redirect to the test.aspx webpage again and again. but I'll use the code you have sent this time and let you know it helps. And if it doesn't work, then i'll give you the code of those webpages. Thanks