MVC 5 Auto Refresh From Controller

2019-08-30 01:25发布

问题:

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");

回答1:

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.