MVC 5 Auto Refresh From Controller

六月ゝ 毕业季﹏ 提交于 2020-01-16 18:33:21

问题


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.



来源:https://stackoverflow.com/questions/28154428/mvc-5-auto-refresh-from-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!