c# ping 一个网站? (保活服务)

发布于 2024-10-04 02:06:29 字数 172 浏览 3 评论 0原文

C# 有没有一种方法可以每 15 分钟 ping 一次 url 并从服务器获取响应?

我想尝试看看 .net 是否可以用来构建一个简单的工具,让 asp.net 网站调用重新构建,以便第一个用户在应用程序启动时不会产生负载损失。

或者如果有人有实现相同目标的替代方法...... 想法?尖端?想法?

is there a way in c# to be able to ping a url every 15 minutes and get a response back from the server?

i want to try to see if .net can be used to build a simple tool to have asp.net websites invoke a re-build so that the first user doesn't incur the load penalty when the application is started.

or if anyone has an alternative method of accomplishing the same goal...
thoughts? tips? ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

原来分手还会想你 2024-10-11 02:06:29

通常,发布版本的人应该在上传网站后进行访问,只是为了测试(确保没有任何内容被炸毁)。但如果您正在寻找一种编程方法,WebClient 可能会有所帮助...

using (WebClient client = new WebClient())
{
  client.DownloadString("http://wwww.sitename.com/");
}

然后将其制作为 exe 并使用 Windows 调度程序来运行它。甚至可以将其放入 WinService 并向日志文件报告状态。

更新:

看起来VS2012现在在发布后打开页面,使那些推送该网站的人成为第一个请求。

另外,如果您发现必须频繁访问它(如问题中提到的每 15 分钟一次),您可能需要考虑重新配置 IIS/AppPool 并将周期时间更改为更长的时间。 IIS 本身会保存未使用的资源,因此,如果某个站点在一段时间内没有被查询,它实际上会释放内存以供其他应用程序使用。

Typically the person pushing a release should visit after they've uploaded the site just for test sake (make sure nothing bombed out). But if you're looking for a programmatic approach, WebClient may be helpful...

using (WebClient client = new WebClient())
{
  client.DownloadString("http://wwww.sitename.com/");
}

Then make it an exe and use the windows scheduler to run it. Could even put this in a WinService and report status to log files.

Update:

It looks like VS2012 now opens the page after a publish, making those pushing the site be the first-request.

Also, if you find you're having to visit it that frequently (every 15 minutes as mentioned in question) you may want to look in to reconfiguring the IIS/AppPool and change the cycle time to something longer. IIS natively conserves resources that are not used, and so if a site hasn't been queried in a while it will actually release the memory for another application to use.

我爱人 2024-10-11 02:06:29

您可以创建一个 HttpWebRequest 并使用类似 Quartz.NET 的内容来安排它。

You could create a HttpWebRequest and use something like Quartz.NET to schedule it.

冷…雨湿花 2024-10-11 02:06:29

您可以只触发 WebRequest - ping 不会让网站重建。

You can just fire off a WebRequest - a ping won't get the website to rebuild.

平生欢 2024-10-11 02:06:29

我会安装 curl 并使用计划任务来执行您想要的操作。

我也将它与 powershell 结合起来重新启动应用程序池。

I'd install curl and use a scheduled task to do what you want.

I've combined it with powershell to restart app pools too.

深府石板幽径 2024-10-11 02:06:29

您可以 NGEN 您的 ASP.NET 程序集并将其与 赫克托热身回答

You can NGEN your ASP.NET assemblies and combine that with Hector's warm-up answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文