0

I am trying to load a excel file, from a local webserver, then refresh the page every 5min or so, just incase that file has been replaced...

It is for displaying a schedule, someone will update it and throughout the plant, the page will be displayed on a monitor and the output will change...

I thought this was going to be super simple, and I would just add a refresh to the header of the .html file and be done, but I think that would only work if I just use the regular return View();... Since I am using Redirect, I am unsure if it is able to add this to the header or not... Any ideas?

Here is the code that I added to my controller:

this.HttpContext.Response.AddHeader("refresh", "5; url=" + Url.Action("time"));
        return Redirect("http://dexweb/scheduler/hunting template.htm");

enter image description here

Kyle Rickaby
  • 117
  • 4
  • 15
  • 1
    You should see my question/answer [How to implement real time data for a web page](http://stackoverflow.com/questions/25829343/how-to-implement-real-time-data-for-a-web-page) which I created specifically to address questions like this. It explains how to use AJAX or SignalR to keep data on a webpage updated when the underlying data changes. – mason Jan 26 '15 at 16:36
  • 2
    why would you add a screen shot of your code instead of your actual code? – Liam Jan 26 '15 at 16:38
  • Because it is two lines of added code... – Kyle Rickaby Jan 26 '15 at 16:39
  • @KyleRickaby It's much better to embed the code in your question as text rather than a picture. Code is text, not pictures. It makes it difficult for someone to answer your question, because if they want to include the code in their answer they have to manually type it all out. – mason Jan 26 '15 at 17:03

1 Answers1

3

It appears that you are redirecting to some HTML page:

http://dexweb/scheduler/hunting_template.htm

Inside this html you could put a <meta> tag to force it to refresh from the server at regular intervals:

<meta http-equiv="refresh" content="5">

Obviously nowadays there are more advanced ways to achieve real time push notifications from the server to the client such as HTML5 WebSockets.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I cant do that, because the person who will be changing the template will be creating new files each time, not editing the current one in existence. – Kyle Rickaby Jan 26 '15 at 16:39
  • Can't this person put the meta tag inside his template? – Darin Dimitrov Jan 26 '15 at 16:40
  • It begins with a excel file, and it was hard enough to show them how to save it as a webpage, let alone go in and edit it :D – Kyle Rickaby Jan 26 '15 at 16:40
  • I understand. Unfortunately there's not much you can do from your MVC application since you are redirecting to a completely different website. You have no way to control the behavior of those external websites. How about the person giving you access to the directory where those templates are created and then before redirecting you can go ahead and *patch* the markup by adding the meta tag? – Darin Dimitrov Jan 26 '15 at 16:41
  • Would it be possible to add a javascript to fake click on the screen then? Then I could make a Post ActionResult that would just reload the page? – Kyle Rickaby Jan 26 '15 at 16:43
  • 2
    Hmm, here's another thing that comes to mind. Instead of redirecting to the target html template you can render a view of your website. This view will only contain an ` – Darin Dimitrov Jan 26 '15 at 16:44
  • Hrmm... I dont know – Kyle Rickaby Jan 26 '15 at 16:46
  • The iframe would allow you to control the hosting webpage and be able to refresh it at regular intervals. – Darin Dimitrov Jan 26 '15 at 16:49
  • I like it, I am testing it now... Once I get height/width figured out I think it will work nicely! – Kyle Rickaby Jan 26 '15 at 16:53
  • Have you tried: `` – Darin Dimitrov Jan 26 '15 at 16:55
  • That worked!! Thank you @DarinDimitrov for your suggestion, the iframe will work perfectly! :D – Kyle Rickaby Jan 26 '15 at 18:05