Asp. How to achieve the same time in net only one person can modify system data

Source: Internet
Author: User
asp.net| data

Some special systems require the same time, only one person can modify the system data, when other people modify the data, in the "lock" state, only those who modify the data when the other people can modify the operation.

By setting a global switch variable (application), when the first user modifies the data, the variable is changed to a value that represents the lock state (for example, Lock), and the other user, before modifying the data, checks to see if it can be modified. Usually the right to release the modification (set the variable to unlock)
1. Users who modify the data exit the system
2. Users who modify the data do not operate for a long time
3. The user who modifies the data closes IE

In the first case, we can handle it when the user clicks the "Exit" button.

In the second case, the user does not operate for a long time we can handle in the Session_End event, this time length can be set in Web.config
(The trigger condition of the Session_End event, Session.Abandon () or a long time operation can trigger the event)

In the third case, the user closes IE, if does not handle this kind of situation, actually is not the application object forever in the lock state, ie closes after the Session_End event still can trigger, namely the system will wait until Session_End event triggers can release this resource, But this is not very good, if the trigger Session_End event time is 1 hours ... In this case, we can enter JavaScript in the page, when the user closes the page, jump to a processing exit page, processing finished immediately automatically shut down.
function Window_onunload () {
{
if (Event.clientx < 0 && Event.clienty < 0)
window.open (' logout.aspx ', ', ', ' Toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, Resizable=no,top=2000,left=2000,width=0,height=0 ');
}
We unlock the application variable on the logout.aspx page

This problem also exists in some other applications, such as the real time online user list for a website



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.