I would like to create an expiration system for my website, where a user pays for a certain period of time, then their account expires. What I need is a way of making them expire. I was thinking to have a method that would run once daily and disable any user that is past the expiration date, but I don’t know how to implement that, because all that I have done so far relies on a person connecting. this code should be independent from somebody visiting the site.
Edit:
Thanks for all of the ideas.
I thought to mention, I can not complete all of the task with just a job on the SQL server. I would need to move and modify files as well.
Something like this:
public void checkExpire()
{
// much more code to check the expiration goes here
if (DateTime.Now == expiration)
{
MembershipUser user = Membership.GetUser();
user.IsApproved = false;
Membership.UpdateUser(user);
File.Move(Request.PhysicalApplicationPath + "logs\\" + user.UserName + ".xml", Request.PhysicalApplicationPath + "logs\\disabled\\" + user.UserName + ".xml");
File.Move(Request.PhysicalApplicationPath + "reps\\" + user.UserName + ".xml", Request.PhysicalApplicationPath + "reps\\disabled\\" + user.UserName + ".xml");
email mail = new email("", true);
mail.sendMail(user.UserName, "Dear user, \n\nYour account has been disabled. None of your data has been lost.\nIf you believe this was a mistake please contact the administrator", "Account Disabled");
Response.Redirect("/Restricted/Members.aspx");
}
}
I was looking at Quartz.net, would that allow me to do that?
Solved:
Thanks to Chris Marisic, who recommended Quartz.net. It allowed me to start a custom event at any interval that I wanted. for asp net, I created a button that only admin could see, that would start the event. Tutorial #3 on the quartz website was mainly what I used.
This question revolves around basic task scheduling which is a nontrivial task to implement.
I would recommend taking a look at Quartz.NET or the Sql Server Job Agent to acheive a system similar to the suggestions from @Nicklamont.