开发者

Run method with no active connection

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.PhysicalAppl开发者_如何学编程icationPath + "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.


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜