没有活动连接的运行方法

发布于 2024-11-18 13:17:23 字数 1340 浏览 0 评论 0原文

我想为我的网站创建一个过期系统,用户在一段时间内付费,然后他们的帐户就会过期。我需要的是一种让它们过期的方法。我正在考虑有一种方法可以每天运行一次并禁用任何超过过期日期的用户,但我不知道如何实现它,因为到目前为止我所做的一切都依赖于一个人的连接。该代码应该独立于访问该网站的人。

编辑:

感谢您的所有想法。

我想提一下,我无法仅通过 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。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淤浪 2024-11-25 13:17:23

这个问题围绕基本任务调度,这是一项需要实现的重要任务。

我建议您查看 Quartz.NET 或 Sql Server Job Agent 以实现与建议类似的系统来自@Nicklamont。

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.

爱你不解释 2024-11-25 13:17:23

您可以在数据库中有一个表,其中包含用户名、活动日期、到期日期列。除了对用户进行身份验证之外,还要检查他们的帐户在此表中是否仍然处于活动状态。

按照你所说的方法,你每天跑步一次。检查所有具有当天到期日期的帐户,并将活动字段设置为 false。

希望能给你一些想法,GL

You could have a table in your DB for this that has username, active, expiration date columns. Along with authenticating the user, check that their account is still active with this table.

In the method you speak that you would run once daily. Check for all accounts that have expiration date of that day, and set active field to false.

Hope that gives ya some ideas, GL

香草可樂 2024-11-25 13:17:23

在数据库中创建 SQL 作业。每晚运行一次。
您可以选择、更新或删除所有您想要的不良用户。
它独立于 C# 代码,并且速度相当快,因为​​它将在 SQL Server 上运行。

如何:创建 Transact-SQL 作业步骤 (SQL Server Management Studio)

Create an SQL job in your database. Run it every night.
You can select, update or delete all bad users you want.
It is independent of C# code, and it is quite fast because it will run on SQL server.

How to: Create a Transact-SQL Job Step (SQL Server Management Studio)

司马昭之心 2024-11-25 13:17:23

编写一个控制台应用程序来进行检查。如果您有权访问服务器的计划任务,请将其添加为您喜欢的运行频率。如果您不知道如何创建控制台应用程序,请参阅以下 MSDN 教程:

http://msdn.microsoft.com/en-us/library/0wc2kk78%28v=vs.90%29.aspx

Write a console application to do the checking. If you have access to the server's scheduled tasks, add it to run however often you like. If you don't know how to create a console app, here is an MSDN tutorial :

http://msdn.microsoft.com/en-us/library/0wc2kk78%28v=vs.90%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文