简体   繁体   English

在ASP.NET中的特定时间刷新页面

[英]Refresh Page on a Specific Time in ASP.NET

I want to refresh a page on a specific time. 我想在特定时间刷新页面。

From http-equiv="refresh" content="30" the page is refresh very 30 seconds,But I want page is refreshed on the specific time. http-equiv="refresh" content="30"页面刷新非常30秒,但我希望页面在特定时间刷新。 like page is refresh on 1:30 of every day. 喜欢页面每天1:30刷新。

You could use javascript to create a countdown timer that starts when the page is loaded in the browser? 您可以使用javascript创建倒计时器,该计时器在页面加载到浏览器时启动?

Add this to your page: 将其添加到您的页面:

<script language="javascript" type="text/javascript">
  setTimeout("window.location = 'yourpage.aspx'", <%= CalcMilisecsToNext130pm() %>);
</script>

You could probably hack something together inline to get the number of milliseconds until 1:30pm. 你可能可以在线一起破解一些东西以获得直到下午1:30的毫秒数。 Else just create simple method in your codebehind... 否则只需在代码隐藏中创建简单的方法......

DateTime targetDate = ...;
long secondsTilRefresh = Math.Floor((targetDate - DateTime.Now).TotalSeconds);

Then, just use that value to fill the meta refresh tag. 然后,只需使用该值填充元刷新标记。 Of course, their browser may not remain open that long, and/or the browser may not support large values. 当然,他们的浏览器可能不会长时间保持打开状态,和/或浏览器可能不支持大值。

Refreshing the page means sending a request to the server. 刷新页面意味着向服务器发送请求。 You can write a Windows Service that sends a request to your page every day at 1:30. 您可以编写一个Windows服务,每天1:30向您的页面发送请求。

I'd suggest you use JavaScript on page load to calculate the time difference between now and when you want to next load the page. 我建议您在页面加载时使用JavaScript来计算现在和下次加载页面之间的时差。 Then set a timeout (window.setInterval) to occur at that time. 然后设置当时发生的超时(window.setInterval)。 Then you can set the JavaScript "location" to the same page and presto - page loads at the scheduled time. 然后,您可以将JavaScript“位置”设置为同一页面,并在预定时间设置presto页面加载。

Jakob beat me to it! 雅各布打败了我! :) :)

Server time put this: 服务器时间这个:

<% DateTime dte = DateTime.Now; %>
<meta http-equiv="refresh" content="<%=86400 - (((dte.Hour * 60) + dte.Minute) * 60) %>">

for client based time use the javascript setTimeout method. 对于基于客户端的时间使用javascript setTimeout方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM