Asked by:
Only one person allowed access to specific page at a time

Question
-
User1864322503 posted
I have a page that I must only allow one person to use at a time, if no one is currently using it, then you have access. I'm having issues with multiple people submitting forms simultaneously and stuff is getting mixed up.
Is there a good way to enforce only one user is on "Page X" at a time?
Thursday, September 18, 2014 3:34 PM
All replies
-
User-484054684 posted
You could try as below:
Set an application variable (can have values as 1 or 0). Use global.asax events.on Session_Start
Check if the value is "1"
- If so, throw the user away.
else
Make it to "1" andmake it to "0" during Session_End.
EDIT: The above is for one user per application. However, looks like you also need one user per one page!
In such case, you may need to update the variable with in the page_load of the page to 1. But there is no mechanism to make it to 0 unless you use a button or something that the user can trigger.Thursday, September 18, 2014 3:37 PM -
User-1336211562 posted
Hi nvielbig,
I agree with Siva,
Besides, you could also add a static class and declare a static fields:
public static class IsLocked { public static Boolean Islocked { get; set; } }
Then, when someone access the PageX page, you could check the value of Islocked, if it is false, redirect to the PageX page and change the value, if it is true, return to current page. After he/she leave the page, change the value.
Best Regards,
LutherSaturday, September 27, 2014 9:20 AM -
User-760709272 posted
I have a page that I must only allow one person to use at a time, if no one is currently using it, then you have access. I'm having issues with multiple people submitting forms simultaneously and stuff is getting mixed up.
Is there a good way to enforce only one user is on "Page X" at a time?
How do you define "using a page"? If I navigate to your page am I using it? If I look at it for 5 minutes am I using it? If I leave my browser open while I'm away for lunch am I using it? The server has no idea if people are "using" a page or not. What you should do is fix the issues you're having around forms being submitted at the same time. If you explain that problem in more detail someone might be able to help.
Saturday, September 27, 2014 9:40 AM -
User753101303 posted
Hi,
The real issue is having issues with multiple people submitting the form. So rather than trying to add more code to prevent this you should fix your code so that the original issue doesn't happen any more.
Could it be that you are using static members? They have the same value of ALL users so using static members rather than instance members is a good way to cause issues when multiple people are using the same data...
Monday, October 6, 2014 8:17 AM -
User1002530435 posted
Hi,
To check there is only one user/session at a time,you should use global.asax [session_start] event and get the sessioncount.If sessioncount=1,you write response.redirect page to the sepcific page or else redirect to the default page.This is just an idea.
Monday, October 13, 2014 7:53 AM -
User1864322503 posted
All,
I re-wrote this entire page, so having two users simultaneously submit will no longer cause an issue.
Monday, October 13, 2014 8:39 AM -
User831885415 posted
can you try this
1. Define a class where you can do the process
public class ProcessClass { public static bool IsInprocess { get; set; } public static void DoProcess()//define params and return type { if (!IsInprocess) { ProcessClass.IsInprocess = true; //do the process } } }
2. In page, in submit event handler, let us say user click on a button to submits the data. handle like this
protected void button1_click(object sender, EventArgs e) { if(ProcessClass.IsInprocess) { lblMessage.Text = "Already in process, try after some time"; return; } ProcessClass.DoProcess(); lblMessage.Text = "Process compleeted successfully"; ProcessClass.IsInprocess = false; }
Thursday, October 16, 2014 3:08 AM