我想为我的网站创建一个过期系统,用户在一段时间内付费,然后他们的帐户就会过期。我需要的是一种让它们过期的方法。我正在考虑有一种方法可以每天运行一次并禁用任何超过过期日期的用户,但我不知道如何实现它,因为到目前为止我所做的一切都依赖于一个人的连接。该代码应该独立于访问该网站的人。
编辑:
感谢所有的想法。
我想提一下,仅靠 SQL 服务器上的一个作业我无法完成所有任务。我还需要移动和修改文件。
类似这样的事情:
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");
}
}
我正在查看 Quartz.net,这可以让我这样做吗?
已解决:
感谢 Chris Marisic 推荐了 Quartz.net。它允许我以我想要的任何时间间隔开始自定义事件。对于 asp net,我创建了一个只有管理员才能看到的按钮,它将启动事件。我使用的主要是quartz网站上的教程#3。
最佳答案
这个问题围绕基本任务调度展开,这是一项需要实现的重要任务。
我建议您查看 Quartz.NET或 Sql Server 作业代理来实现类似于@Nicklamont 建议的系统。
关于c# - 没有事件连接的运行方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6601076/