?
Solved

MVC - Ensure launched page is not cached

Posted on 2013-06-20
4
Medium Priority
?
278 Views
Last Modified: 2013-06-20
Hi:

I have an MVC 4 app in which the controller launches a page showing all of the student's lessons and a button beside each that the student can press to launch the lesson.  There is also an check mark beside each lesson showing whether that student has previously launched the lesson.  

The controller code to launch the lessons page looks like this:

public ActionResult EnrollmentModules(int id)
        {
            //Get list of all student's lessons with checkmark beside each showing completion status and button to launch
            var enrollment = _enrollmentsRepository.GetById(id);
            @ViewBag.PageTitle = enrollment.Course.Name;
            return View(_moduleRecordsRepository.GetModuleRecordsByEnrollment(enrollment));
        }

Open in new window


Now the student goes away in a flash module - takes the lesson and when s/he finishes, the  _enrollmentsRepository and database are updated indicating that the student has completed the lesson.  

I then have a bit of javascript that brings the user back to my page that launched the lesson.  

It looks something like this:

qs = "http://myOriginalCallingApp.com?StudentId=27;
            top.document.location.href =  qs;

Open in new window

"

This worked fine when I was using a forms application.  The user was redirected to the page which loaded the updated records and showed the lesson has having been completion.

With MVC, however, I get the original cached version of the page and have to do a browser refresh in order to see the check mark beside the recently completed lesson.

I have tried various things such as

var destination = top.document.location = qs;
destination.reload(true);

Open in new window


but am still unable to return to the calling page with refreshed data.  

Any help in solving this greatly appreciated.

RBS
0
Comment
Question by:RBS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 1500 total points
ID: 39264601
What about :
var destination = top.document.location = qs + "&_t=" + new Date().getTime();
0
 

Author Comment

by:RBS
ID: 39264679
Thank you for the suggestion - when I try it however, I get the error message:

"A potentially dangerous Request.Path value was detected from the client (&)."

RBS
0
 

Author Closing Comment

by:RBS
ID: 39264715
I replaced the "&_t"  with "?t" and it worked like a charm!

Thanks,
RBS
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39264804
You said :
It looks something like this:

qs = "http://myOriginalCallingApp.com?StudentId=27;

I see a question mark here, so I'm not sure why you add a new one...
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question