开发者

running C# web app with schedular in microsoft server

I have a web application developed in C# that retrieves data from a database and writes the retrieved to a file. What i need to do is to be able to run this web app regularly on my server(Microsoft server), say once a day to update the data. I think using开发者_StackOverflow社区 a schedular would be the way to do it but I don't know how to get it to run my web app i.e my .sln file. I looked at the post below for ideas: Running a web app automatically but need a little more guidance.


You could write a console application which will send an HTTP request to the web application:

class Program
{
    static void Main()
    {
        using (var client = new WebClient())
        {
            var result = client.DownloadString("http://example.com/test.aspx");
            File.WriteAllText("foo.txt", result);
        }
    }
}

and then configure the Windows Scheduler to run this console application at given time.


Use a Windows Scheduled Task. If you need to run in the web context, have the scheduled task retrieve a url, that will kick off the processing.


Here is a sample VB script that can be called by the task scheduler to make an ASP.NET page be executed.

Even if this kind of solution is quite common, it is not really a good one. If you have regular maintenance tasks that need to run daily, create a console app that does that and call that directly from scheduled tasks. If you need to run it more frequently, or respond to other events a Windows Service is better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜