How to perform periodic work on an ASP.NET MVC website?

后端 未结 4 535
深忆病人
深忆病人 2020-12-06 01:04

Once a day, I want my ASP.NET MVC4 website, which may be running on multiple servers, to email a report to me. This seems like a pretty common thing to want to do, but I\'m

相关标签:
4条回答
  • 2020-12-06 01:30

    I would recommend running Quartz.NET as a Windows Service:

    Quartz.NET - Enterprise Job Scheduler for .NET Platform

    There's boilerplate code for a Windows Service in the download.

    0 讨论(0)
  • 2020-12-06 01:40

    A few options:

    • If you are hosting on Azure as a Website, check out WebJobs which was released recently in preview (http://azure.microsoft.com/en-us/documentation/articles/web-sites-create-web-jobs/)
    • If you don't want the pain of extracting out your email logic outside of the website, expose that functionality at a url (with a handler, mvc action, etc.) and then run a Windows Scheduled task that hits that url on a schedule.
    • Write a simple console app that is executed similarly via a Windows Scheduled task.
    • Or write a simple Windows Service that internally is looping and checking the time and when reached, hits that url, runs that exe, or has it's own code to send you the email.
    0 讨论(0)
  • 2020-12-06 01:41

    The proper solution is to create a background service that runs independently of your website. However, if that is not an option there is a hack where you can use the cache as explained in Easy Background Tasks in ASP.NET by Jeff Atwood.

    0 讨论(0)
  • 2020-12-06 01:51

    You should not be doing this task from your web application as Phil Haack nicely explains it in his blog post.

    How is this sort of thing normally done?

    You could perform this task from a Windows Service or even a console application that is scheduled to run at regular intervals using the Windows Scheduler.

    0 讨论(0)
提交回复
热议问题