Search code examples
datetimeasp.net-mvc-5content-expiration

How to set objects to begin/expire at date/time in MVC 5


As part of the requirements for my project, I need to set up objects so that they begin/expire. This has to be done without a user actually going to the page, as I need to set up notifications for these events. Meaning it has to run without user interaction. I already have a date/time start/end property for each of the objects. What is the best way of doing this?


Solution

  • Publishing/expiring is not a function of watching for the date to occur and doing something; you merely take those dates into account when querying objects from your database. For example, if you were dealing with a blog, in your index view, you would only bring in posts that are "published" based on the appropriate date column.

    Now as far as notification goes, that's a case where you'll need some process that checks the date values on a regular basis. You can't (or at least shouldn't) do this with your web application, since web servers are not designed to handle long running tasks.

    Revalee is a project you might want to check out. It allows you to schedule tasks to be run in an external process from your web application.