且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在asp.net中限制用户注册者的数量

更新时间:2023-12-02 13:47:34

oid Application_Start(object sender, EventArgs e)
{
    Application["ActiveSessions"] = 0;
}

void Session_Start(object sender, EventArgs e)
{
    try
    {
        Application.Lock();

        int activeSessions = (int) Application["ActiveSessions"] + 1;
        int allowedSessions = 10; // retrieve the threshold here instead

        Application["ActiveSessions"] = activeSessions;

        if (activeSessions > allowedSessions)
            System.Web.HttpContext.Current.Response.Redirect("~/UserLimitReached.aspx", false);
    }
    finally
    {
        Application.UnLock();
    }
}

void Session_End(object sender, EventArgs e)
{
    Application.Lock();
    Application["ActiveSessions"] = (int)Application["ActiveSessions"] - 1;
    Application.UnLock();
}


oid Application_Start(object sender, EventArgs e)
{
    Application["ActiveSessions"] = 0;
}

void Session_Start(object sender, EventArgs e)
{
    try
    {
        Application.Lock();

        int activeSessions = (int) Application["ActiveSessions"] + 1;
        int allowedSessions = 10; // retrieve the threshold here instead

        Application["ActiveSessions"] = activeSessions;

        if (activeSessions > allowedSessions)
            System.Web.HttpContext.Current.Response.Redirect("~/UserLimitReached.aspx", false);
    }
    finally
    {
        Application.UnLock();
    }
}

void Session_End(object sender, EventArgs e)
{
    Application.Lock();
    Application["ActiveSessions"] = (int)Application["ActiveSessions"] - 1;
    Application.UnLock();
}


你可以在存储过程中处理这个问题,你应该检查一下userid并且在每个用户的日期没有交易,你可以很容易地得到在插入新注册之前插入了多少条记录。
you can handle this in stored procedure, you should check with userid and no of transaction per user on the date, you can easily get how many records inserted before you insert a new registration.