如何每隔5分钟运行一次在Iis中托管的Aspx页面? [英] How Do I Run A Aspx Page Hosted In Iis On Every 5 Mins?

查看:96
本文介绍了如何每隔5分钟运行一次在Iis中托管的Aspx页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有任何设计的aspx页面。文件后面的代码只有一些代码。我需要每隔5分钟从服务器运行一次这个页面。此页面也无需在任何浏览器上显示。是否有任何选项可供我定期重复运行此页面。没有浏览器会显示,也应该在服务器(IIS)中显示。





我不能使用exe(Windows应用程序)。

I have an aspx page which does not have any design. Only some code on code behind file. I need to run this page on every 5 minutes from server. This page also need not display on any browser. Is there any option available for me to run this page repeatedly on a regular basis. No browser will display and also it should happen in server(IIS).


I can not go with exe(Windows Application).

推荐答案

Scott Hanselman记录了在ASP.NET应用程序中运行后台任务的可用选项:

http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx [





可以使用
新的 QueueBackgroundWorkItem API [ ^ ]。



Scott的建议似乎是使用Hangfire [ ^ ],但他列出了几个其他选项。
Scott Hanselman documented the available options for running background tasks in ASP.NET applications:
http://www.hanselman.com/blog/HowToRunBackgroundTasksInASPNET.aspx[^]

If you're using .NET 4.5.2, you can use the new QueueBackgroundWorkItem API[^].

Scott's recommendation seems to be to use Hangfire[^], but he lists several other options as well.


在Global.ascx页面中写下此代码

Write this code in Global.ascx page
void Application_Start(object sender, EventArgs e)
        {
            try
            {
                new Task(() =>
                {
                    while (true)
                    {
                        WebClient web = new WebClient();
                        web.DownloadData("http://localhost:60749/Default.aspx");
                        System.Threading.Thread.Sleep(300000);
                    }

                }).Start();
            }
            catch (Exception ex)
            {
            }
        }





给你想要在时间间隔中执行页面的页面的URL。

此页面将每5分钟执行一次间隔



give the Url of the page which you want to execute the page in Time intervels.
this page will execute every 5 mints intervel


如果你想要那样的东西,那么使用Windows服务,它可以根据你的时间配置,并调用OnStart()中的方法,而不是使用任何aspx页面。您可以创建它的.exe并运行一次,然后根据您的要求调用方法



请参阅此链接进行开发: Windows服务教程
If you want anything like that then use Windows Service which can be configured as per your timings and would invoke methods in OnStart(), rather then using any aspx page. you can create an .exe of it and run it once and would call the methods as per your requirements

Refer this link for development : Windows service tutorial

这篇关于如何每隔5分钟运行一次在Iis中托管的Aspx页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆